Skip to contentSkip to conversation

some problems about permission of subdirectory

DISCUSSION houlinfei 2 participants 2 messages Feb 23, 2017

Subsystems (2)
lore
Share & tools
lore

houlinfei

author
#0 lore raw

aGkgS2luZ2xvbmcsCkkgdHJ5IGFnYWluLCBpdCdzIG9rYXkuIGJ1dCB3ZSB3YW50IHRvIG1vZGlm eSB0aGUgY29kZSwgdGlsbCBub3cgd2UgYXJlIG5vdCBmYW1pbGlhciB3aXRoIG5mcywgY2FuIHlv dSB0ZWxsIHVzIHdoZXJlIHNob3VsZCB3ZSBtb2RpZnk/CnRoYW5rcywKaG91bGluZmVp

#1 lore raw

Cc Bruce, Steven,

Quoted 2 lines · houlinfei

hi Kinglong,
I try again, it's okay. but we want to modify the code, till now we are not familiar with nfs, can you tell us where should we modify?

The logic is set a mark on the exported dir when exporting dir, nfsd kernel checks the mark when finding export entry.

There are two patches I have a little test, fs/nfsd/vfs.c is the kernel source, and utils/exportfs/exportfs.c is the nfs-utils source.

fs/nfsd/vfs.c +3 -0
index 26c6fdb..c03566c 100644
@@ -456,6 +456,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
  * NFS junction information is stored in an extended attribute.
  */
 #define NFSD_JUNCTION_XATTR_NAME	XATTR_TRUSTED_PREFIX "junction.nfs"
+#define NFSD_EXPORTED_XATTR_NAME	NFSD_JUNCTION_XATTR_NAME ".exported"
 
 /**
  * nfsd4_is_junction - Test if an object could be an NFS junction
@@ -471,6 +472,8 @@ int nfsd4_is_junction(struct dentry *dentry)
 
 	if (inode == NULL)
 		return 0;
+	if (vfs_getxattr(dentry, NFSD_EXPORTED_XATTR_NAME, NULL, 0) > 0)
+		return 1;
 	if (inode->i_mode & S_IXUGO)
 		return 0;
 	if (!(inode->i_mode & S_ISVTX))
utils/exportfs/exportfs.c +4 -0
index 02d5b6d..3c6e36b 100644
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <time.h>
+#include <linux/xattr.h>
 
 #define INT_TO_LONG_THRESHOLD_SECS (INT_MAX - (60 * 60 * 24))
 
@@ -556,6 +557,9 @@ validate_export(nfs_export *exp)
 		return;
 
 	}
+
+#define NFSD_EXPORTED_XATTR_NAME  XATTR_TRUSTED_PREFIX "junction.nfs.exported"
+	setxattr(path, NFSD_EXPORTED_XATTR_NAME, "exported", 8, 0);
 }
 
 static _Bool

thanks,
Kinglong Mee