shithub: gefs

Download patch

ref: b47e9118f1702a695d56974a2a42f466aad7af94
parent: 0b48ffaa5b5ffe4bb1ea88e21bbfede601bb3215
author: Ori Bernstein <[email protected]>
date: Thu May 16 15:28:14 EDT 2024

fs: clean up 'snap' taking

--- a/cons.c
+++ b/cons.c
@@ -72,12 +72,16 @@
 			break;
 		flg = UNPACK32(s.kv.v+1+8);
 		fprint(fd, "snap %.*s", s.kv.nk-1, s.kv.k+1);
+		if(flg != 0)
+			fprint(fd, " [");
 		if(flg & Lmut)
 			fprint(fd, " mutable");
 		if(flg & Lauto)
 			fprint(fd, " auto");
-		if(flg & Lnoauto)
-			fprint(fd, " auto=off");
+		if(flg & Ltsnap)
+			fprint(fd, " tsnap");
+		if(flg != 0)
+			fprint(fd, " ]");
 		fprint(fd, "\n");
 	}
 	btexit(&s);
@@ -95,10 +99,11 @@
 	}
 	a->op = AOsnap;
 	a->fd = fd;
+	a->flag = Ltsnap;
 	while(ap[0][0] == '-'){
 		for(i = 1; ap[0][i]; i++){
 			switch(ap[0][i]){
-			case 'S':	a->flag |= Lnoauto;	break;
+			case 'S':	a->flag &= ~Ltsnap;	break;
 			case 'm':	a->flag |= Lmut;	break;
 			case 'd':	a->delete++;		break;
 			case 'l':
--- a/dat.h
+++ b/dat.h
@@ -118,7 +118,7 @@
 enum {
 	Lmut	= 1 << 0,	/* can we modify snaps via this label */
 	Lauto	= 1 << 1,	/* was this label generated automatically */
-	Lnoauto	= 1 << 2,	/* should we skip the timed snapshots */
+	Ltsnap	= 1 << 2,	/* should we skip the timed snapshots */
 };
 
 enum {
@@ -199,7 +199,7 @@
  *			snapshot.
  *	rooth[8]	hash of root node
  *	narena[4]	number of arenas in tree
- *	flags[8]	feature flags
+ *	flag[8]	feature flag
  *	gen[8]		The flush generation
  *
  * The arena zone blocks have this layout, and
@@ -286,10 +286,10 @@
 
 /*
  * Wstat ops come with associated data, in the order
- * of the bit flags.
+ * of the bit flag.
  */
 enum{
-	/* wstat flags */
+	/* wstat flag */
 	Owsize	= 1<<0,	/* [8]fsize: update file size */
 	Owmode	= 1<<1,	/* [4]mode: update file mode */
 	Owmtime	= 1<<2, /* [8]mtime: update mtime, in nsec */
@@ -495,7 +495,7 @@
 	Tree	snap;
 	Dlist	snapdl;
 	int	narena;
-	vlong	flags;
+	vlong	flag;
 	vlong	nextqid;
 	vlong	nextgen;
 	vlong	qgen;
@@ -597,7 +597,7 @@
 
 struct Xdir {
 	/* file data */
-	uvlong	flag;	/* storage flags */
+	uvlong	flag;	/* storage flag */
 	Qid	qid;	/* unique id from server */
 	ulong	mode;	/* permissions */
 	vlong	atime;	/* last read time: nsec */
@@ -632,8 +632,7 @@
 	char	name[64];
 	Tree	*root;	/* EBR protected */
 
-	char	mutable;
-	char	noauto;
+	int	flag;
 
 	/* snapshot history */
 	char	minutely[60][128];
--- a/fns.h
+++ b/fns.h
@@ -74,7 +74,7 @@
 Mount*	getmount(char*);
 void	clunkmount(Mount*);
 
-void	updatesnap(Tree**, Tree*, char*);
+void	updatesnap(Tree**, Tree*, char*, int);
 void	tagsnap(Tree*, char*, int);
 void	delsnap(Tree*, vlong, char*);
 void	freedl(Dlist*, int);
--- a/fs.c
+++ b/fs.c
@@ -90,7 +90,7 @@
 	qlock(&fs->mutlk);
 	tracem("packb");
 	for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next)
-		updatesnap(&mnt->root, mnt->root, mnt->name);
+		updatesnap(&mnt->root, mnt->root, mnt->name, mnt->flag);
 	/*
 	 * Now that we've updated the snaps, we can sync the
 	 * dlist; the snap tree will not change from here.
@@ -190,7 +190,7 @@
 	*tp = nil;
 	for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
 		if(strcmp(a->old, mnt->name) == 0){
-			updatesnap(&mnt->root, mnt->root, mnt->name);
+			updatesnap(&mnt->root, mnt->root, mnt->name, mnt->flag);
 			t = agetp(&mnt->root);
 			ainc(&t->memref);
 			break;
@@ -401,10 +401,10 @@
 static void
 upsert(Mount *mnt, Msg *m, int nm)
 {
-	if(!mnt->mutable)
+	if(!(mnt->flag & Lmut))
 		error(Erdonly);
 	if(mnt->root->nlbl != 1 || mnt->root->nref != 0)
-		updatesnap(&mnt->root, mnt->root, mnt->name);
+		updatesnap(&mnt->root, mnt->root, mnt->name, mnt->flag);
 	btupsert(mnt->root, m, nm);
 }
 
@@ -625,8 +625,7 @@
 	if((t = opensnap(name, &flg)) == nil)
 		error(Enosnap);
 	loadautos(mnt);
-	mnt->mutable = (flg & Lmut) != 0;
-	mnt->noauto = (flg & Lnoauto) != 0;
+	mnt->flag = flg;
 	mnt->root = t;
 	mnt->next = fs->mounts;
 	asetp(&fs->mounts, mnt);
@@ -2626,7 +2625,7 @@
 
 		tmnow(&now, nil);
 		for(mnt = agetp(&fs->mounts); mnt != nil; mnt = mnt->next){
-			if(mnt->noauto)
+			if(!(mnt->flag & Ltsnap))
 				continue;
 			if(now.yday != then.yday){
 				snprint(buf, sizeof(buf),
--- a/load.c
+++ b/load.c
@@ -132,7 +132,7 @@
 	fprint(2, "load %s:\n", dev);
 	fprint(2, "\tsnaptree:\t%B\n", fs->snap.bp);
 	fprint(2, "\tnarenas:\t%d\n", fs->narena);
-	fprint(2, "\tfeatures:\t%lld\n", fs->flags);
+	fprint(2, "\tfeatures:\t%lld\n", fs->flag);
 	fprint(2, "\tnextqid:\t%lld\n", fs->nextqid);
 	fprint(2, "\tlastqgen:\t%lld\n", fs->qgen);
 	fprint(2, "\tnextgen:\t%lld\n", fs->nextgen);
--- a/pack.c
+++ b/pack.c
@@ -453,7 +453,7 @@
 	PACK64(p, fi->snapdl.hd.hash);	p += 8;
 	PACK64(p, fi->snapdl.tl.addr);	p += 8;
 	PACK64(p, fi->snapdl.tl.hash);	p += 8;
-	PACK64(p, fi->flags);		p += 8;
+	PACK64(p, fi->flag);		p += 8;
 	PACK64(p, fi->nextqid);		p += 8;
 	PACK64(p, fi->nextgen);		p += 8;
 	PACK64(p, fi->qgen);		p += 8;
@@ -493,7 +493,7 @@
 	fi->snapdl.tl.hash = UNPACK64(p);	p += 8;
 	fi->snapdl.hd.gen = -1;			p += 0;
 	fi->snapdl.gen = -1;			p += 0;
-	fi->flags = UNPACK64(p);		p += 8;
+	fi->flag = UNPACK64(p);			p += 8;
 	fi->nextqid = UNPACK64(p);		p += 8;
 	fi->nextgen = UNPACK64(p);		p += 8;
 	fi->qgen = UNPACK64(p);	p += 8;
--- a/ream.c
+++ b/ream.c
@@ -91,11 +91,11 @@
 	Tree t;
 	Kvp kv;
 
-	lbl2kv("adm", 1, Lmut, &kv, buf, sizeof(buf));
+	lbl2kv("adm", 1, Lmut|Ltsnap, &kv, buf, sizeof(buf));
 	setval(s, &kv);
 	lbl2kv("empty", 0, 0, &kv, buf, sizeof(buf));
 	setval(s, &kv);
-	lbl2kv("main", 2, Lmut, &kv, buf, sizeof(buf));
+	lbl2kv("main", 2, Lmut|Ltsnap, &kv, buf, sizeof(buf));
 	setval(s, &kv);
 
 	p = buf;
--- a/snap.c
+++ b/snap.c
@@ -430,7 +430,7 @@
  * immutable.
  */
 void
-updatesnap(Tree **r, Tree *o, char *lbl)
+updatesnap(Tree **r, Tree *o, char *lbl, int flg)
 {
 	char buf[4][Kvmax];
 	Msg m[4];
@@ -479,7 +479,7 @@
 	tree2kv(t, &m[i], buf[i], sizeof(buf[i]));
 	i++;
 	m[i].op = Oinsert;
-	lbl2kv(lbl, t->gen, Lmut, &m[i], buf[i], sizeof(buf[i]));
+	lbl2kv(lbl, t->gen, flg, &m[i], buf[i], sizeof(buf[i]));
 	i++;
 	btupsert(&fs->snap, m, i);