Skip to contentSkip to conversation

PATCH/RFC Add support for using UUID to identify filesystem in filehandle

PATCH Neil Brown 2 participants 3 messages Feb 2, 2007 – Feb 9, 2007

Subsystems (2)
lore
Share & tools
lore

Neil Brown

author
#0 lore raw

If anyone wants to review these patches, or comment on the design, I'd appreciate it....

The way nfsd has identified filesystems has bothered me for a while.

The default mechanism is to use the major/minor device number of the block device that holds the filesystem. This doesn't work for filesystems without a block device, and has problems if the major/minor number changes, as can happen with hardware changes and kernel upgrades.

The alternate introduced some time ago is to explicitly give a number to identify each filesystem with fsid=XXX in /etc/exports. This overcomes the above problems but requires manually assigning numbers which isn't always ideal.

What this patch set does is allow you to use a UUID extracted from the filesystem with libblkid.

UUIDs are 16 bytes long and there is not enough room to store that in an NFSv2 filehandle (along with identification of the file). So for NFSv2 we hash the UUID down to 8 or 4 bytes (using simple xor). If the exportpoint is the root of a filesystem, we use an 8 byte hash. If it is lower in the filesystem we use a 4 byte hash and a 4 byte inode number.

NFSv3 (and v4) filehandles have lots more room, so there we use the full 16byte uuid and an optional 64bit inode number.

Note that with lots of filesystems exported with NFSv2 there is an increased chance of uuid collision. Don't do that. Use v3.

You currently specify the uuid by putting
fsuuid
in the export flags (and you can give an explicit uuid if you want to).
I wonder if I should just over-load fsid, and have
fsid=uuid
(exactly that) to mean use a libblkid uuid, and
fsid=xxxxxxxx:xxxxxxxx:xxxxxxxx:xxxxxxxx
(hex digits for the 'x's) for an explicit uuid.
I would want to be able to specify both an old fsid and a new uuid (for a transition period, to avoid clients suddenly having their file handles rejected) so maybe you can just specify "fsid=" twice.

What do people think?

It would be nice to be able to call-out to a support program if a given uuid didn't match any mounted filesystem. It could then mount the filesystem (maybe from a media-changer) and export it. I haven't implemented that yet.

Maybe even a call-out the get the uuid of a filesystem that libblkid doesn't understand?? Would that be useful?

Maybe 'fsuuid' should be a default. If the kernel supports uuid-filehandles, mounted should always provide a uuid to the kernel and hand out uuid filehandles whenever appropriate.... Or maybe it should only default on v3, as on v2 there is a small chance that you can break a working setup.

Thought? comments? Testing? Review?

Thanks,
NeilBrown

Below are two patches to the kernel - against latest -mm -followed by an nfs-utils patch against latest git... I made up the changes to configure.in. If anyone understands recommended practice for that file and can comment :-)

-----------------------------------------------

Tidy up choice of filesystem-identifier when creating a filehandle.

If we are using the same version/fsid as a current filehandle, then there is no need to verify the the numbers are valid for this export, and they must be (we used them to find this export).

This allows us to simplify the fsid selection code.

Also change "ref_fh_version" and "ref_fh_fsid_type" to "version" and "fsid_type", as the important thing isn't that they are the version/type of the reference filehandle, but they are the chosen type for the new filehandle.

And tidy up some indenting.

### Diffstat output

 ./fs/nfsd/nfsfh.c |  124 ++++++++++++++++++++++++++----------------------------
 1 file changed, 60 insertions(+), 64 deletions(-)
fs/nfsd/nfsfh.c +60 -64
diff .prev/fs/nfsd/nfsfh.c ./fs/nfsd/nfsfh.c
@@ -211,7 +211,7 @@ fh_verify(struct svc_rqst *rqstp, struct
 				fileid_type = 2;
 		} else
 			fileid_type = fh->fh_fileid_type;
-		
+
 		if (fileid_type == 0)
 			dentry = dget(exp->ex_dentry);
 		else {
@@ -291,7 +291,7 @@ static inline int _fh_update(struct dent
 			     __u32 *datap, int *maxsize)
 {
 	struct export_operations *nop = exp->ex_mnt->mnt_sb->s_export_op;
-	
+
 	if (dentry == exp->ex_dentry) {
 		*maxsize = 0;
 		return 0;
@@ -316,7 +316,8 @@ static inline void _fh_update_old(struct
 }
 
 __be32
-fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry, struct svc_fh *ref_fh)
+fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
+	   struct svc_fh *ref_fh)
 {
 	/* ref_fh is a reference file handle.
 	 * if it is non-null and for the same filesystem, then we should compose
@@ -326,8 +327,8 @@ fh_compose(struct svc_fh *fhp, struct sv
 	 *
 	 */
 
-	u8 ref_fh_version = 0;
-	u8 ref_fh_fsid_type = 0;
+	u8 version = 1;
+	u8 fsid_type = 0;
 	struct inode * inode = dentry->d_inode;
 	struct dentry *parent = dentry->d_parent;
 	__u32 *datap;
@@ -339,57 +340,52 @@ fh_compose(struct svc_fh *fhp, struct sv
 		parent->d_name.name, dentry->d_name.name,
 		(inode ? inode->i_ino : 0));
 
+	/* Choose filehandle version and fsid type based on
+	 * the reference filehandle (if it is in the same export)
+	 * or the export options.
+	 */
 	if (ref_fh && ref_fh->fh_export == exp) {
-		ref_fh_version = ref_fh->fh_handle.fh_version;
-		if (ref_fh_version == 0xca)
-			ref_fh_fsid_type = 0;
+		version = ref_fh->fh_handle.fh_version;
+		if (version == 0xca)
+			fsid_type = 0;
 		else
-			ref_fh_fsid_type = ref_fh->fh_handle.fh_fsid_type;
-		if (ref_fh_fsid_type > 3)
-			ref_fh_fsid_type = 0;
-
-		/* make sure ref_fh type works for given export */
-		if (ref_fh_fsid_type == 1 &&
-		    !(exp->ex_flags & NFSEXP_FSID)) {
-			/* if we don't have an fsid, we cannot provide one... */
-			ref_fh_fsid_type = 0;
-		}
+			fsid_type = ref_fh->fh_handle.fh_fsid_type;
+		/* We know this version/type works for this export
+		 * so there is no need for further checks.
+		 */
 	} else if (exp->ex_flags & NFSEXP_FSID)
-		ref_fh_fsid_type = 1;
-
-	if (!old_valid_dev(ex_dev) && ref_fh_fsid_type == 0) {
+		fsid_type = 1;
+	else if (!old_valid_dev(ex_dev))
 		/* for newer device numbers, we must use a newer fsid format */
-		ref_fh_version = 1;
-		ref_fh_fsid_type = 3;
-	}
-	if (old_valid_dev(ex_dev) &&
-	    (ref_fh_fsid_type == 2 || ref_fh_fsid_type == 3))
-		/* must use type1 for smaller device numbers */
-		ref_fh_fsid_type = 0;
+		fsid_type = 3;
+	else
+		fsid_type = 0;
 
 	if (ref_fh == fhp)
 		fh_put(ref_fh);
 
 	if (fhp->fh_locked || fhp->fh_dentry) {
 		printk(KERN_ERR "fh_compose: fh %s/%s not initialized!\n",
-			parent->d_name.name, dentry->d_name.name);
+		       parent->d_name.name, dentry->d_name.name);
 	}
 	if (fhp->fh_maxsize < NFS_FHSIZE)
 		printk(KERN_ERR "fh_compose: called with maxsize %d! %s/%s\n",
-		       fhp->fh_maxsize, parent->d_name.name, dentry->d_name.name);
+		       fhp->fh_maxsize,
+		       parent->d_name.name, dentry->d_name.name);
 
 	fhp->fh_dentry = dget(dentry); /* our internal copy */
 	fhp->fh_export = exp;
 	cache_get(&exp->h);
 
-	if (ref_fh_version == 0xca) {
+	if (version == 0xca) {
 		/* old style filehandle please */
 		memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
 		fhp->fh_handle.fh_size = NFS_FHSIZE;
 		fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
 		fhp->fh_handle.ofh_dev =  old_encode_dev(ex_dev);
 		fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
-		fhp->fh_handle.ofh_xino = ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
+		fhp->fh_handle.ofh_xino =
+			ino_t_to_u32(exp->ex_dentry->d_inode->i_ino);
 		fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
 		if (inode)
 			_fh_update_old(dentry, exp, &fhp->fh_handle);
@@ -398,38 +394,38 @@ fh_compose(struct svc_fh *fhp, struct sv
 		fhp->fh_handle.fh_version = 1;
 		fhp->fh_handle.fh_auth_type = 0;
 		datap = fhp->fh_handle.fh_auth+0;
-		fhp->fh_handle.fh_fsid_type = ref_fh_fsid_type;
-		switch (ref_fh_fsid_type) {
-			case 0:
-				/*
-				 * fsid_type 0:
-				 * 2byte major, 2byte minor, 4byte inode
-				 */
-				mk_fsid_v0(datap, ex_dev,
-					exp->ex_dentry->d_inode->i_ino);
-				break;
-			case 1:
-				/* fsid_type 1 == 4 bytes filesystem id */
-				mk_fsid_v1(datap, exp->ex_fsid);
-				break;
-			case 2:
-				/*
-				 * fsid_type 2:
-				 * 4byte major, 4byte minor, 4byte inode
-				 */
-				mk_fsid_v2(datap, ex_dev,
-					exp->ex_dentry->d_inode->i_ino);
-				break;
-			case 3:
-				/*
-				 * fsid_type 3:
-				 * 4byte devicenumber, 4byte inode
-				 */
-				mk_fsid_v3(datap, ex_dev,
-					exp->ex_dentry->d_inode->i_ino);
-				break;
+		fhp->fh_handle.fh_fsid_type = fsid_type;
+		switch (fsid_type) {
+		case 0:
+			/*
+			 * fsid_type 0:
+			 * 2byte major, 2byte minor, 4byte inode
+			 */
+			mk_fsid_v0(datap, ex_dev,
+				   exp->ex_dentry->d_inode->i_ino);
+			break;
+		case 1:
+			/* fsid_type 1 == 4 bytes filesystem id */
+			mk_fsid_v1(datap, exp->ex_fsid);
+			break;
+		case 2:
+			/*
+			 * fsid_type 2:
+			 * 4byte major, 4byte minor, 4byte inode
+			 */
+			mk_fsid_v2(datap, ex_dev,
+				   exp->ex_dentry->d_inode->i_ino);
+			break;
+		case 3:
+			/*
+			 * fsid_type 3:
+			 * 4byte devicenumber, 4byte inode
+			 */
+			mk_fsid_v3(datap, ex_dev,
+				   exp->ex_dentry->d_inode->i_ino);
+			break;
 		}
-		len = key_len(ref_fh_fsid_type);
+		len = key_len(fsid_type);
 		datap += len/4;
 		fhp->fh_handle.fh_size = 4 + len;
 
@@ -456,7 +452,7 @@ fh_update(struct svc_fh *fhp)
 {
 	struct dentry *dentry;
 	__u32 *datap;
-	
+
 	if (!fhp->fh_dentry)
 		goto out_bad;
 

------------------------------------------------------------------------

Add some new fsid types.

Add support for 8 and 16 byte fsid types, so that
filesystem uuids can be used.
Larger ones will only be used for NFSv3+

### Diffstat output

 ./fs/nfsd/export.c            |   67 +++++++++++++++++++++++++++++++-----------
 ./fs/nfsd/nfsfh.c             |   27 ++++++++++++++++
 ./include/linux/nfsd/export.h |    7 ++--
 ./include/linux/nfsd/nfsfh.h  |   31 +++++++++++++++++++
 4 files changed, 112 insertions(+), 20 deletions(-)
fs/nfsd/export.c +50 -17

134 lines not on this page · raw message

fs/nfsd/nfsfh.c +27 -0
diff .prev/fs/nfsd/nfsfh.c ./fs/nfsd/nfsfh.c
@@ -333,6 +333,7 @@ fh_compose(struct svc_fh *fhp, struct sv
 	struct dentry *parent = dentry->d_parent;
 	__u32 *datap;
 	dev_t ex_dev = exp->ex_dentry->d_inode->i_sb->s_dev;
+	int root_export = (exp->ex_dentry == exp->ex_dentry->d_sb->s_root);
 
 	dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %s/%s, ino=%ld)\n",
 		MAJOR(ex_dev), MINOR(ex_dev),
@@ -353,6 +354,18 @@ fh_compose(struct svc_fh *fhp, struct sv
 		/* We know this version/type works for this export
 		 * so there is no need for further checks.
 		 */
+	} else if (exp->ex_uuid) {
+		if (fhp->fh_maxsize >= 64) {
+			if (root_export)
+				fsid_type = 6;
+			else
+				fsid_type = 7;
+		} else {
+			if (root_export)
+				fsid_type = 5;
+			else
+				fsid_type = 4;
+		}
 	} else if (exp->ex_flags & NFSEXP_FSID)
 		fsid_type = 1;
 	else if (!old_valid_dev(ex_dev))
@@ -424,6 +437,20 @@ fh_compose(struct svc_fh *fhp, struct sv
 			mk_fsid_v3(datap, ex_dev,
 				   exp->ex_dentry->d_inode->i_ino);
 			break;
+		case 4:
+			mk_fsid_v4(datap, exp->ex_uuid,
+				   exp->ex_dentry->d_inode->i_ino);
+			break;
+		case 5:
+			mk_fsid_v5(datap, exp->ex_uuid);
+			break;
+		case 6:
+			mk_fsid_v6(datap, exp->ex_uuid);
+			break;
+		case 7:
+			mk_fsid_v7(datap, exp->ex_uuid,
+				   exp->ex_dentry->d_inode->i_ino);
+			break;
 		}
 		len = key_len(fsid_type);
 		datap += len/4;
include/linux/nfsd/export.h +4 -3
diff .prev/include/linux/nfsd/export.h ./include/linux/nfsd/export.h
@@ -74,19 +74,20 @@ struct svc_export {
 	uid_t			ex_anon_uid;
 	gid_t			ex_anon_gid;
 	int			ex_fsid;
+	unsigned char *		ex_uuid; /* 16 byte fsid */
 	struct nfsd4_fs_locations ex_fslocs;
 };
 
 /* an "export key" (expkey) maps a filehandlefragement to an
- * svc_export for a given client.  There can be two per export, one
- * for type 0 (dev/ino), one for type 1 (fsid)
+ * svc_export for a given client.  There can be several per export,
+ * for the different fsid types.
  */
 struct svc_expkey {
 	struct cache_head	h;
 
 	struct auth_domain *	ek_client;
 	int			ek_fsidtype;
-	u32			ek_fsid[3];
+	u32			ek_fsid[6];
 
 	struct vfsmount *	ek_mnt;
 	struct dentry *		ek_dentry;
include/linux/nfsd/nfsfh.h +31 -0
diff .prev/include/linux/nfsd/nfsfh.h ./include/linux/nfsd/nfsfh.h
@@ -190,6 +190,33 @@ static inline void mk_fsid_v3(u32 *fsidv
 	fsidv[1] = ino_t_to_u32(ino);
 }
 
+static inline void mk_fsid_v4(u32 *fsidv, unsigned char *uuid, ino_t ino)
+{
+	/* 4 byte fsid and inode number */
+	u32 *up = (u32*)uuid;
+	fsidv[0] = ino_t_to_u32(ino);
+	fsidv[1] = up[0] ^ up[1] ^ up[2] ^ up[3];
+}
+
+static inline void mk_fsid_v5(u32 *fsidv, unsigned char *uuid)
+{
+	/* 8 byte fsid  */
+	u32 *up = (u32*)uuid;
+	fsidv[0] = up[0] ^ up[2];
+	fsidv[1] = up[1] ^ up[3];
+}
+static inline void mk_fsid_v6(u32 *fsidv, unsigned char *uuid)
+{
+	/* 16 byte fsid - NFSv3+ only */
+	memcpy(fsidv, uuid, 16);
+}
+static inline void mk_fsid_v7(u32 *fsidv, unsigned char *uuid, ino_t ino)
+{
+	/* 8 byte inode and 16 byte fsid */
+	*(u64*)fsidv = (u64)ino;
+	memcpy(fsidv+2, uuid, 16);
+}
+
 static inline int key_len(int type)
 {
 	switch(type) {
@@ -197,6 +224,10 @@ static inline int key_len(int type)
 	case 1: return 4;
 	case 2: return 12;
 	case 3: return 8;
+	case 4: return 8;
+	case 5: return 8;
+	case 6: return 16;
+	case 7: return 24;
 	default: return 0;
 	}
 }

---------------------------------------------------------------

configure.in +3 -0
index 7cec002..279e260 100644
@@ -174,9 +174,12 @@ fi
 if test "$knfsd_cv_glibc2" = no; then
     AC_CHECK_LIB(bsd, daemon, [LIBBSD="-lbsd"])
 fi
+AC_CHECK_LIB(blkid, blkid_get_cache, [LIBBLKID="-lblkid"], AC_MSG_ERROR([libblkid needed]))
+AC_CHECK_HEADER(blkid/blkid.h, , AC_MSG_ERROR([Cannot file libblkid header file blkid/blkid.h]))
 AC_SUBST(LIBSOCKET)
 AC_SUBST(LIBCRYPT)
 AC_SUBST(LIBBSD)
+AC_SUBST(LIBBLKID)
 
 if test "$enable_gss" = yes; then
   dnl 'gss' also depends on nfsidmap.h - at least for svcgssd_proc.c
support/include/nfslib.h +1 -0
index aba37c2..13a89da 100644
@@ -80,6 +80,7 @@ struct exportent {
 	int		e_nsqgids;
 	int		e_fsid;
 	char *		e_mountpoint;
+	char *		e_uuid;
 };
 
 struct rmtabent {
support/nfs/cacheio.c +6 -3
index 36473cf..407da93 100644
@@ -247,8 +247,9 @@ cache_flush(int force)
 	int c;
 	char stime[20];
 	char path[200];
+	time_t now;
 	/* Note: the order of these caches is important.
-	 * The need to be flushed in dependancy order. So
+	 * They need to be flushed in dependancy order. So
 	 * a cache that references items in another cache,
 	 * as nfsd.fh entries reference items in nfsd.export,
 	 * must be flushed before the cache that it references.
@@ -259,9 +260,11 @@ cache_flush(int force)
 		"nfsd.export",
 		NULL
 	};
+	now = time(0);
 	if (force ||
-	    stat(_PATH_ETAB, &stb) != 0)
-		stb.st_mtime = time(0);
+	    stat(_PATH_ETAB, &stb) != 0 ||
+		stb.st_mtime > now)
+		stb.st_mtime = now;
 	
 	sprintf(stime, "%ld\n", stb.st_mtime);
 	for (c=0; cachelist[c]; c++) {
support/nfs/exports.c +20 -5
index 2d31781..c3a3154 100644
@@ -96,6 +96,7 @@ getexportent(int fromkernel, int fromexports)
 	ee.e_mountpoint = NULL;
 	ee.e_nsquids = 0;
 	ee.e_nsqgids = 0;
+	ee.e_uuid = NULL;
 
 	if (first || (ok = getexport(exp, sizeof(exp))) == 0) {
 		ok = getpath(ee.e_path, sizeof(ee.e_path));
@@ -196,6 +197,11 @@ putexportent(struct exportent *ep)
 	if (ep->e_flags & NFSEXP_FSID) {
 		fprintf(fp, "fsid=%d,", ep->e_fsid);
 	}
+	if (ep->e_uuid == (char*)1)
+		fprintf(fp, "fsuuid,");
+	else if (ep->e_uuid)
+		fprintf(fp, "fsuuid=%s,", ep->e_uuid);
+
 	if (ep->e_mountpoint)
 		fprintf(fp, "mountpoint%s%s,",
 			ep->e_mountpoint[0]?"=":"", ep->e_mountpoint);
@@ -278,6 +284,7 @@ mkexportent(char *hname, char *path, char *options)
 	ee.e_mountpoint = NULL;
 	ee.e_nsquids = 0;
 	ee.e_nsqgids = 0;
+	ee.e_uuid = NULL;
 
 	if (strlen(hname) >= sizeof(ee.e_hostname)) {
 		xlog(L_WARNING, "client name %s too long", hname);
@@ -421,13 +428,21 @@ bad_option:
 			}
 		} else if (strncmp(opt, "fsid=", 5) == 0) {
 			char *oe;
-			ep->e_fsid = strtoul(opt+5, &oe, 0);
-			if (opt[5]=='\0' || *oe != '\0') {
-				xlog(L_ERROR, "%s: %d: bad fsid \"%s\"\n",
-				     flname, flline, opt);	
-				goto bad_option;
+			if (strcmp(opt+5, "root") == 0)
+				ep->e_fsid = 0;
+			else {
+				ep->e_fsid = strtoul(opt+5, &oe, 0);
+				if (opt[5]=='\0' || *oe != '\0') {
+					xlog(L_ERROR, "%s: %d: bad fsid \"%s\"\n",
+					     flname, flline, opt);	
+					goto bad_option;
+				}
 			}
 			ep->e_flags |= NFSEXP_FSID;
+		} else if (strcmp(opt, "fsuuid") == 0) {
+			ep->e_uuid = (char*)1;
+		} else if (strncmp(opt, "fsuuid=", 7) == 0) {
+			ep->e_uuid = strdup(opt+7);
 		} else if (strcmp(opt, "mountpoint")==0 ||
 			   strcmp(opt, "mp") == 0 ||
 			   strncmp(opt, "mountpoint=", 11)==0 ||
support/nfs/nfssvc.c +1 -1
index ef7d8e1..72ee48c 100644
@@ -95,7 +95,7 @@ nfssvc_setfds(int port, unsigned int ctlbits, char *haddr)
 		snprintf(buf, BUFSIZ,"%d\n", udpfd); 
 		if (write(fd, buf, strlen(buf)) != strlen(buf)) {
 			syslog(LOG_ERR, 
-			       "nfssvc: writting fds to kernel failed: errno %d (%s)", 
+			       "nfssvc: writing fds to kernel failed: errno %d (%s)", 
 			       errno, strerror(errno));
 		}
 		close(fd);
utils/exportfs/exportfs.c +4 -0
index cd49a3b..06058ff 100644
@@ -404,6 +404,10 @@ dump(int verbose)
 				c = dumpopt(c, "no_acl");
 			if (ep->e_flags & NFSEXP_FSID)
 				c = dumpopt(c, "fsid=%d", ep->e_fsid);
+			if (ep->e_uuid == (char*)1)
+				c = dumpopt(c, "fsuuid");
+			else if (ep->e_uuid)
+				c = dumpopt(c, "fsuuid=%s", ep->e_uuid);
 			if (ep->e_mountpoint)
 				c = dumpopt(c, "mountpoint%s%s", 
 					    ep->e_mountpoint[0]?"=":"", 
utils/exportfs/exports.man +23 -1
index d57b8b4..960c5bd 100644
@@ -301,7 +301,7 @@ then the nominated path must be a mountpoint for the exportpoint to be
 exported.
 
 .TP
-.IR fsid= num
+.IR fsid= num|root
 This option forces the filesystem identification portion of the file
 handle and file attributes used on the wire to be
 .I num
@@ -322,6 +322,28 @@ The value  0 has a special meaning when use with NFSv4.  NFSv4 has a
 concept of a root of the overall exported filesystem. The export point
 exported with fsid=0 will be used as this root.
 
+.TP
+.IR fsuuid
+.TP
+.IR fsuuid= uuid
+This is an alternate to
+.IR fsid .
+If a uuid is given (32 hex digits with arbitrary punctuation), it
+behaves very like
+.I fsid
+except that the filesystem identifier can contain more bits, so
+creating a unique uuid is easier.
+
+If no
+.I uuid
+is given, the UUID of the filesystem being exported is used if such is
+available.  This is extracted using
+.IR libblkid .
+This allows filesystems to be safely exported without concern for the
+device number changing, and without needing to manually assign device
+numbers.
+
+
 .SS User ID Mapping
 .PP
 .I nfsd
utils/mountd/Makefile.am +1 -1
index dd400fd..c8500cb 100644
@@ -12,7 +12,7 @@ mountd_SOURCES = mountd.c mount_dispatch.c auth.c rmtab.c cache.c \
 mountd_LDADD = ../../support/export/libexport.a \
 	       ../../support/nfs/libnfs.a \
 	       ../../support/misc/libmisc.a \
-	       $(LIBBSD) $(LIBWRAP) $(LIBNSL)
+	       $(LIBBSD) $(LIBWRAP) $(LIBNSL) $(LIBBLKID)
 mountd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \
 		  -I$(top_builddir)/support/include \
 		  -I$(top_srcdir)/support/export
utils/mountd/cache.c +151 -6

222 lines not on this page · raw message

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw
Quoted 55 lines · Neil Brown

If anyone wants to review these patches, or comment on the design, I'd appreciate it....

The way nfsd has identified filesystems has bothered me for a while.

The default mechanism is to use the major/minor device number of the block device that holds the filesystem. This doesn't work for filesystems without a block device, and has problems if the major/minor number changes, as can happen with hardware changes and kernel upgrades.

The alternate introduced some time ago is to explicitly give a number to identify each filesystem with fsid=XXX in /etc/exports. This overcomes the above problems but requires manually assigning numbers which isn't always ideal.

What this patch set does is allow you to use a UUID extracted from the filesystem with libblkid.

UUIDs are 16 bytes long and there is not enough room to store that in an NFSv2 filehandle (along with identification of the file). So for NFSv2 we hash the UUID down to 8 or 4 bytes (using simple xor). If the exportpoint is the root of a filesystem, we use an 8 byte hash. If it is lower in the filesystem we use a 4 byte hash and a 4 byte inode number.

NFSv3 (and v4) filehandles have lots more room, so there we use the full 16byte uuid and an optional 64bit inode number.

Note that with lots of filesystems exported with NFSv2 there is an increased chance of uuid collision. Don't do that. Use v3.

You currently specify the uuid by putting
fsuuid
in the export flags (and you can give an explicit uuid if you want to).
I wonder if I should just over-load fsid, and have
fsid=uuid
(exactly that) to mean use a libblkid uuid, and
fsid=xxxxxxxx:xxxxxxxx:xxxxxxxx:xxxxxxxx
(hex digits for the 'x's) for an explicit uuid.
I would want to be able to specify both an old fsid and a new uuid (for a transition period, to avoid clients suddenly having their file handles rejected) so maybe you can just specify "fsid=" twice.

What do people think?

It would be nice to be able to call-out to a support program if a given uuid didn't match any mounted filesystem. It could then mount the filesystem (maybe from a media-changer) and export it. I haven't implemented that yet.

Maybe even a call-out the get the uuid of a filesystem that libblkid doesn't understand?? Would that be useful?

Quoted 7 lines

Maybe 'fsuuid' should be a default. If the kernel supports uuid-filehandles, mounted should always provide a uuid to the kernel and hand out uuid filehandles whenever appropriate.... Or maybe it should only default on v3, as on v2 there is a small chance that you can break a working setup.

Thought? comments? Testing? Review?

I like the idea of using a UUID. That makes server setup infinitely more easy, and should definitely be the default.

What are the filesystems that support 16 byte UUIDs these days? Should we also support hashed labels for those that do not?

About the code. It would really be nice if you could avoid all these open-coded filehandle version numbers and fsid types. Use of a macro or enum to name them would certainly help the casual code reviewer. Also, names like "mk_fsid_v7" do tend to confuse. Perhaps something like mk_fsid_uuid() and mk_fsid_uuid_root_export() (for v6)?

Cheers,
Trond

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

author
#2 lore raw
Quoted 6 lines · On Friday February 2, [email protected] wrote:

I like the idea of using a UUID. That makes server setup infinitely more easy, and should definitely be the default.

What are the filesystems that support 16 byte UUIDs these days? Should we also support hashed labels for those that do not?

libblkid seems to find 16byte uuids for
ext2, ext3, xfs, reiserfs, reiser4, jfs, ocfs, ocfs2

So that excludes FAT (which has a 4 byte uuid), minix, ISO9660, UDF and some very minor filesystems.

ISO9660 seems to be the only significant one that has a label but not a uuid.

Quoted 6 lines

About the code. It would really be nice if you could avoid all these open-coded filehandle version numbers and fsid types. Use of a macro or enum to name them would certainly help the casual code reviewer. Also, names like "mk_fsid_v7" do tend to confuse. Perhaps something like mk_fsid_uuid() and mk_fsid_uuid_root_export() (for v6)?

Fair comment. I'll have a look and a think and see what makes it most readable.

Thanks,
NeilBrown

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs