ref: b682b7eb92eac118212e711590277cf432a65710
parent: 20446deff8dae32ae7a921adbd278a1da898b26c
author: 9ferno <gophone2015@gmail.com>
date: Thu Oct 13 09:35:13 EDT 2022
storing service into the config
--- a/all.h
+++ b/all.h
@@ -82,10 +82,10 @@
void freeblockbuf(Iobuf *buf);
void freeblocks(u64 blkno, u16 len, u16 tag, u64 qpath);
void fsok(int ok);
-void init(int doream);
+void init(int doream, char *service);
u64 newqpath();
u64 nperiblock(u16 tag);
-void ream(u64 size);
+void ream(u64 size, char *service);
void rel2abs(Dentry *d, u64 reli, Spanid *s);
void rmfile(u64 qpath, u64 dblkno);
void rmdirectory(u64 qpath, u64 dblkno);
@@ -93,7 +93,7 @@
Dentry *searchdir(u64 dblkno, u64 qpath, u16 uid, char *searchname, u64 searchidx, Iobuf **dbuf, Iobuf **buf);
void shutdown(void);
void start9p(char *service, char **nets, int stdio);
-void superream(u64 size, u64 nblocks);
+void superream(u64 size, u64 nblocks, char *service);
Tlock* tlocked(Iobuf*, Dentry*);
/* dentry routines */
--- a/config.c
+++ b/config.c
@@ -57,6 +57,8 @@
panic("mafs: %s initconfig(): invalid size\n", service);
if((config.root.dest[1] = atoll(tokens[++i])) == 0)
panic("mafs: %s initconfig(): invalid size\n", service);
+ }else if(strcmp(tokens[i], "service") == 0){
+ strncpy(config.service, tokens[++i], Namelen);
}
}
if(chatty9p)
@@ -66,6 +68,7 @@
"backup config %llud to %llud %llud\n"
"backup super %llud to %llud %llud\n"
"backup root %llud to %llud %llud\n",
+ "service %s\n",
config.size,
config.nblocks,
config.config.srcbno,
@@ -76,7 +79,8 @@
config.super.dest[1],
config.root.srcbno,
config.root.dest[0],
- config.root.dest[1]);
+ config.root.dest[1],
+ config.service);
}
void
@@ -93,7 +97,8 @@
"nblocks %llud\n"
"backup config %llud to %llud %llud\n"
"backup super %llud to %llud %llud\n"
- "backup root %llud to %llud %llud\n",
+ "backup root %llud to %llud %llud\n"
+ "service %s",
config.size,
config.nblocks,
config.config.srcbno,
@@ -104,7 +109,8 @@
config.super.dest[1],
config.root.srcbno,
config.root.dest[0],
- config.root.dest[1]);
+ config.root.dest[1],
+ config.service);
if(n == Blocksize)
panic("config needs more blocks");
if(chatty9p)
--- a/dat.h
+++ b/dat.h
@@ -296,6 +296,7 @@
struct Bkp config;
struct Bkp super;
struct Bkp root;
+ char service[Namelen];
};
enum
--- a/docs/mafs.ms
+++ b/docs/mafs.ms
@@ -1047,11 +1047,11 @@
Ream and start single process Mafs on a disk and also mount it for use.
.sp
.nf
- mount -c <{disk/mafs -s -r -h 10 mydisk myservice <[0=1]} /n/mafs_myservice
+ mount -c <{disk/mafs -s -r mafs_myservice -h 10 mydisk <[0=1]} /n/mafs_myservice
.in 3n
.br
-s: use stdin and stdout for communication
- -r: ream the disk
+ -r myservice: ream the disk using mafs_myservice as the service name
-h 10: use 10 hash buckets
mydisk: running Mafs on the mydisk
.in 0
@@ -1060,7 +1060,7 @@
Ream and start multiple-process mafs on a disk.
.sp
.nf
- disk/mafs -r -h 10 mydisk myservice
+ disk/mafs -r mafs_myservice -h 10 mydisk
mount -c /srv/mafs_myservice /n/mafs_myservice
.fi
.sp
@@ -1068,10 +1068,10 @@
.sp
.nf
dd -if /dev/zero -of myfile -bs 512 -count 128 # 64KB file
- mount -c <{disk/mafs -s -r -h 10 myfile service <[0=1]} /n/mafs_myservice
+ mount -c <{disk/mafs -s -r mafs_service -h 10 myfile <[0=1]} /n/mafs_myservice
# for reusing the contents of myfile later, remove -r (ream).
- mount -c <{disk/mafs -s -h 10 myfile service <[0=1]} /n/mafs_myservice
+ mount -c <{disk/mafs -s -h 10 myfile <[0=1]} /n/mafs_myservice
.fi
.sp
Prepare and use a disk (/dev/sdF1) for mafs.
@@ -1083,7 +1083,7 @@
w
p
q' | disk/prep -b /dev/sdF1/plan9 # add an fs plan 9 partition to the disk
- disk/mafs -r /dev/sdF1/fs sdF1 # -r to ream the disk
+ disk/mafs -r mafs_sdF1 /dev/sdF1/fs # -r to ream the disk
mount -c /srv/mafs_sdF1 /n/mafs_sdF1
# for using the mafs file system on the disk later on
@@ -1125,8 +1125,8 @@
.sp
dd -if /dev/zero -of disk.file -bs 512 -count 4096;
.br
- mount -c <{disk/mafs -s -r 4 -m 1 -n mafs_disk.file \\
- disk.file <[0=1]} /n/mafs_disk.file
+ mount -c <{disk/mafs -s -r mafs_disk.file -m 1 -n mafs_disk.file \\
+ <[0=1]} /n/mafs_disk.file
.fi
.sp
tests/sizes.c shows the maximum file size representable by a Dentry.
binary files a/docs/mafs.pdf b/docs/mafs.pdf differ
--- a/mafs.c
+++ b/mafs.c
@@ -15,7 +15,7 @@
char *procname;
char *devfile = nil; /* device file path */
-char service[Namelen];
+char service[Namelen] = "\0";
u8 noauth = 0;
u8 readonly = 0;
u8 shuttingdown = 0;
@@ -32,7 +32,7 @@
static void
usage(void)
{
- fprint(2, "usage: mafs [-Drs] [-h nbuckets] [-a announce-string]... fsfile service\n");
+ fprint(2, "usage: mafs [-Ds] [-r service] [-n service] [-h nbuckets] [-a announce-string]... fsfile\n");
exits("usage");
}
@@ -41,7 +41,7 @@
{
static char *nets[8];
int doream, stdio, netc;
- char buf[Namelen], *srvname;
+ char buf[Namelen];
int pid, ctl;
progname = "mafs";
@@ -69,7 +69,12 @@
case 'D': chatty9p++; break;
case 'f': devfile = ARGF(); break;
case 'h': nbuckets = atoi(EARGF(usage())); break;
- case 'r': doream = 1; break;
+ case 'r':
+ doream = 1;
+ /* fall through */
+ case 'n':
+ strncpy(service, EARGF(usage()), Namelen);
+ break;
case 's': stdio++; break;
case 'a':
if(netc >= nelem(nets)-1){
@@ -80,7 +85,7 @@
break;
}ARGEND
- if(argc != 2)
+ if(argc != 1 || (doream && service[0] == '\0'))
usage();
devfile = argv[0];
@@ -87,11 +92,6 @@
if(devfile == nil)
sysfatal("no disk file");
- if((srvname = estrdup9p(argv[1])) == nil)
- usage();
- else
- sprint(service, "mafs_%s", srvname);
-
if(chatty9p){
print("\nPlan 9 %d-bit file server with %d-deep indirect blocks\n",
sizeof(u64)*8, Niblock);
@@ -109,11 +109,15 @@
/*
* init the file system, ream it if needed, and get the block sizes
*/
- init(doream);
+ init(doream, service);
- start9p(service, nets, stdio);
+ if(service[0] == '\0')
+ start9p(config.service, nets, stdio);
+ else
+ start9p(service, nets, stdio);
+
/*
- we have started another proc to process /srv/mafs_service
+ we have started another proc to process /srv/service
and it is my time to exit
*/
exits(nil);
--- a/sub.c
+++ b/sub.c
@@ -365,7 +365,7 @@
}
void
-superream(u64 size, u64 nblocks)
+superream(u64 size, u64 nblocks, char *service)
{
Iobuf *sbuf;
Superb *s;
@@ -421,6 +421,7 @@
config.config.srcbno = Bconfig;
config.super.srcbno = Bsuper;
config.root.srcbno = Broot;
+ strncpy(config.service, service, Namelen);
fsok(0);
}
@@ -428,7 +429,7 @@
char magic[] = "mafs device\n";
/* TODO open the dev file OEXCL? */
void
-ream(u64 size)
+ream(u64 size, char *service)
{
char buf[Rawblocksize];
int i;
@@ -451,7 +452,7 @@
for(i = 0; i < Nbused; i++)
devwrite(i, buf, 1);
- superream(size, nblocks);
+ superream(size, nblocks, service);
iob = getbuf(Bmagicb, 1, Bmod);
snprint((s8*)iob->io->buf+256, Rawblocksize-256, "%s%d\n%llud\n",
@@ -490,7 +491,7 @@
}
void
-init(int doream)
+init(int doream, char *service)
{
u32 rbufsize, maxspansize;
u64 size;
@@ -503,7 +504,7 @@
panic("null size %s", devfile);
if(doream)
- ream(size);
+ ream(size, service);
else{
initconfig(Bconfig);
loadfrees(Bdfrees);
--- a/tests/regress.rc
+++ b/tests/regress.rc
@@ -24,9 +24,9 @@
# start service
if(~ $"debug '')
- mount -c <{disk/mafs -s -r -h 10 $disk $service <[0=1]} /n/mafs_^$service
+ mount -c <{disk/mafs -s -r mafs_^$service -h 10 $disk <[0=1]} /n/mafs_^$service
if not
- mount -c <{disk/mafs $"debug -s -r -h 10 $disk $service <[0=1]} /n/mafs_^$service
+ mount -c <{disk/mafs $"debug -s -r mafs_^$service -h 10 $disk <[0=1]} /n/mafs_^$service
echo service status: $status
sleep 1
@@ -62,9 +62,9 @@
# start service
if(~ $"debug '')
- disk/mafs -r -h 10 $disk $service
+ disk/mafs -r mafs_^$service -h 10 $disk
if not
- disk/mafs $"debug -r -h 10 $disk $service
+ disk/mafs $"debug -r mafs_^$service -h 10 $disk
echo service status: $status
mount -c /srv/mafs_^$service /n/mafs_^$service
--- a/tests/test.0/blocks/1
+++ b/tests/test.0/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.0
--- a/tests/test.0/blocks/24
+++ b/tests/test.0/blocks/24
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.0
--- a/tests/test.0/blocks/31
+++ b/tests/test.0/blocks/31
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.0
--- a/tests/test.1/blocks/1
+++ b/tests/test.1/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.1
--- a/tests/test.1/blocks/24
+++ b/tests/test.1/blocks/24
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.1
--- a/tests/test.1/blocks/31
+++ b/tests/test.1/blocks/31
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.1
--- a/tests/test.2/blocks/1
+++ b/tests/test.2/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 39 28
backup super 2 to 38 27
backup root 3 to 37 26
+service mafs_test.2
--- a/tests/test.2/blocks/28
+++ b/tests/test.2/blocks/28
@@ -4,3 +4,4 @@
backup config 1 to 39 28
backup super 2 to 38 27
backup root 3 to 37 26
+service mafs_test.2
--- a/tests/test.2/blocks/39
+++ b/tests/test.2/blocks/39
@@ -4,3 +4,4 @@
backup config 1 to 39 28
backup super 2 to 38 27
backup root 3 to 37 26
+service mafs_test.2
--- a/tests/test.3/blocks/1
+++ b/tests/test.3/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 40959 20488
backup super 2 to 40958 20487
backup root 3 to 40957 20486
+service mafs_test.3
--- a/tests/test.3/blocks/20488
+++ b/tests/test.3/blocks/20488
@@ -4,3 +4,4 @@
backup config 1 to 40959 20488
backup super 2 to 40958 20487
backup root 3 to 40957 20486
+service mafs_test.3
--- a/tests/test.3/blocks/40959
+++ b/tests/test.3/blocks/40959
@@ -4,3 +4,4 @@
backup config 1 to 40959 20488
backup super 2 to 40958 20487
backup root 3 to 40957 20486
+service mafs_test.3
--- a/tests/test.6/blocks/1
+++ b/tests/test.6/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.6
--- a/tests/test.6/blocks/24
+++ b/tests/test.6/blocks/24
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.6
--- a/tests/test.6/blocks/31
+++ b/tests/test.6/blocks/31
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.6
--- a/tests/test.8/blocks/1
+++ b/tests/test.8/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 25 21
backup super 2 to 24 20
backup root 3 to 23 19
+service mafs_test.8
--- a/tests/test.8/blocks/21
+++ b/tests/test.8/blocks/21
@@ -4,3 +4,4 @@
backup config 1 to 25 21
backup super 2 to 24 20
backup root 3 to 23 19
+service mafs_test.8
--- a/tests/test.8/blocks/25
+++ b/tests/test.8/blocks/25
@@ -4,3 +4,4 @@
backup config 1 to 25 21
backup super 2 to 24 20
backup root 3 to 23 19
+service mafs_test.8
--- a/tests/test.9/blocks/1
+++ b/tests/test.9/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 131071 65544
backup super 2 to 131070 65543
backup root 3 to 131069 65542
+service mafs_test.9
--- a/tests/test.b/blocks/1
+++ b/tests/test.b/blocks/1
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.b
--- a/tests/test.b/blocks/24
+++ b/tests/test.b/blocks/24
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.b
--- a/tests/test.b/blocks/31
+++ b/tests/test.b/blocks/31
@@ -4,3 +4,4 @@
backup config 1 to 31 24
backup super 2 to 30 23
backup root 3 to 29 22
+service mafs_test.b