⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 export.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* flags */	err = get_int(&mesg, &an_int);	if (err == -ENOENT) {		err = 0;		set_bit(CACHE_NEGATIVE, &exp.h.flags);	} else {		if (err || an_int < 0) goto out;			exp.ex_flags= an_int;			/* anon uid */		err = get_int(&mesg, &an_int);		if (err) goto out;		exp.ex_anon_uid= an_int;		/* anon gid */		err = get_int(&mesg, &an_int);		if (err) goto out;		exp.ex_anon_gid= an_int;		/* fsid */		err = get_int(&mesg, &an_int);		if (err) goto out;		exp.ex_fsid = an_int;		while ((len = qword_get(&mesg, buf, PAGE_SIZE)) > 0) {			if (strcmp(buf, "fsloc") == 0)				err = fsloc_parse(&mesg, buf, &exp.ex_fslocs);			else if (strcmp(buf, "uuid") == 0) {				/* expect a 16 byte uuid encoded as \xXXXX... */				len = qword_get(&mesg, buf, PAGE_SIZE);				if (len != 16)					err  = -EINVAL;				else {					exp.ex_uuid =						kmemdup(buf, 16, GFP_KERNEL);					if (exp.ex_uuid == NULL)						err = -ENOMEM;				}			} else if (strcmp(buf, "secinfo") == 0)				err = secinfo_parse(&mesg, buf, &exp);			else				/* quietly ignore unknown words and anything				 * following. Newer user-space can try to set				 * new values, then see what the result was.				 */				break;			if (err)				goto out;		}		err = check_export(nd.dentry->d_inode, exp.ex_flags,				   exp.ex_uuid);		if (err) goto out;	}	expp = svc_export_lookup(&exp);	if (expp)		expp = svc_export_update(&exp, expp);	else		err = -ENOMEM;	cache_flush();	if (expp == NULL)		err = -ENOMEM;	else		exp_put(expp); out:	nfsd4_fslocs_free(&exp.ex_fslocs);	kfree(exp.ex_uuid); 	kfree(exp.ex_path);	if (nd.dentry)		path_release(&nd); out_no_path:	if (dom)		auth_domain_put(dom);	kfree(buf);	return err;}static void exp_flags(struct seq_file *m, int flag, int fsid,		uid_t anonu, uid_t anong, struct nfsd4_fs_locations *fslocs);static void show_secinfo(struct seq_file *m, struct svc_export *exp);static int svc_export_show(struct seq_file *m,			   struct cache_detail *cd,			   struct cache_head *h){	struct svc_export *exp ;	if (h ==NULL) {		seq_puts(m, "#path domain(flags)\n");		return 0;	}	exp = container_of(h, struct svc_export, h);	seq_path(m, exp->ex_mnt, exp->ex_dentry, " \t\n\\");	seq_putc(m, '\t');	seq_escape(m, exp->ex_client->name, " \t\n\\");	seq_putc(m, '(');	if (test_bit(CACHE_VALID, &h->flags) && 	    !test_bit(CACHE_NEGATIVE, &h->flags)) {		exp_flags(m, exp->ex_flags, exp->ex_fsid,			  exp->ex_anon_uid, exp->ex_anon_gid, &exp->ex_fslocs);		if (exp->ex_uuid) {			int i;			seq_puts(m, ",uuid=");			for (i=0; i<16; i++) {				if ((i&3) == 0 && i)					seq_putc(m, ':');				seq_printf(m, "%02x", exp->ex_uuid[i]);			}		}		show_secinfo(m, exp);	}	seq_puts(m, ")\n");	return 0;}static int svc_export_match(struct cache_head *a, struct cache_head *b){	struct svc_export *orig = container_of(a, struct svc_export, h);	struct svc_export *new = container_of(b, struct svc_export, h);	return orig->ex_client == new->ex_client &&		orig->ex_dentry == new->ex_dentry &&		orig->ex_mnt == new->ex_mnt;}static void svc_export_init(struct cache_head *cnew, struct cache_head *citem){	struct svc_export *new = container_of(cnew, struct svc_export, h);	struct svc_export *item = container_of(citem, struct svc_export, h);	kref_get(&item->ex_client->ref);	new->ex_client = item->ex_client;	new->ex_dentry = dget(item->ex_dentry);	new->ex_mnt = mntget(item->ex_mnt);	new->ex_path = NULL;	new->ex_fslocs.locations = NULL;	new->ex_fslocs.locations_count = 0;	new->ex_fslocs.migrated = 0;}static void export_update(struct cache_head *cnew, struct cache_head *citem){	struct svc_export *new = container_of(cnew, struct svc_export, h);	struct svc_export *item = container_of(citem, struct svc_export, h);	int i;	new->ex_flags = item->ex_flags;	new->ex_anon_uid = item->ex_anon_uid;	new->ex_anon_gid = item->ex_anon_gid;	new->ex_fsid = item->ex_fsid;	new->ex_uuid = item->ex_uuid;	item->ex_uuid = NULL;	new->ex_path = item->ex_path;	item->ex_path = NULL;	new->ex_fslocs.locations = item->ex_fslocs.locations;	item->ex_fslocs.locations = NULL;	new->ex_fslocs.locations_count = item->ex_fslocs.locations_count;	item->ex_fslocs.locations_count = 0;	new->ex_fslocs.migrated = item->ex_fslocs.migrated;	item->ex_fslocs.migrated = 0;	new->ex_nflavors = item->ex_nflavors;	for (i = 0; i < MAX_SECINFO_LIST; i++) {		new->ex_flavors[i] = item->ex_flavors[i];	}}static struct cache_head *svc_export_alloc(void){	struct svc_export *i = kmalloc(sizeof(*i), GFP_KERNEL);	if (i)		return &i->h;	else		return NULL;}struct cache_detail svc_export_cache = {	.owner		= THIS_MODULE,	.hash_size	= EXPORT_HASHMAX,	.hash_table	= export_table,	.name		= "nfsd.export",	.cache_put	= svc_export_put,	.cache_request	= svc_export_request,	.cache_parse	= svc_export_parse,	.cache_show	= svc_export_show,	.match		= svc_export_match,	.init		= svc_export_init,	.update		= export_update,	.alloc		= svc_export_alloc,};static struct svc_export *svc_export_lookup(struct svc_export *exp){	struct cache_head *ch;	int hash;	hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS);	hash ^= hash_ptr(exp->ex_dentry, EXPORT_HASHBITS);	hash ^= hash_ptr(exp->ex_mnt, EXPORT_HASHBITS);	ch = sunrpc_cache_lookup(&svc_export_cache, &exp->h,				 hash);	if (ch)		return container_of(ch, struct svc_export, h);	else		return NULL;}static struct svc_export *svc_export_update(struct svc_export *new, struct svc_export *old){	struct cache_head *ch;	int hash;	hash = hash_ptr(old->ex_client, EXPORT_HASHBITS);	hash ^= hash_ptr(old->ex_dentry, EXPORT_HASHBITS);	hash ^= hash_ptr(old->ex_mnt, EXPORT_HASHBITS);	ch = sunrpc_cache_update(&svc_export_cache, &new->h,				 &old->h,				 hash);	if (ch)		return container_of(ch, struct svc_export, h);	else		return NULL;}static struct svc_expkey *exp_find_key(svc_client *clp, int fsid_type, u32 *fsidv, struct cache_req *reqp){	struct svc_expkey key, *ek;	int err;		if (!clp)		return ERR_PTR(-ENOENT);	key.ek_client = clp;	key.ek_fsidtype = fsid_type;	memcpy(key.ek_fsid, fsidv, key_len(fsid_type));	ek = svc_expkey_lookup(&key);	if (ek == NULL)		return ERR_PTR(-ENOMEM);	err = cache_check(&svc_expkey_cache, &ek->h, reqp);	if (err)		return ERR_PTR(err);	return ek;}static int exp_set_key(svc_client *clp, int fsid_type, u32 *fsidv,		       struct svc_export *exp){	struct svc_expkey key, *ek;	key.ek_client = clp;	key.ek_fsidtype = fsid_type;	memcpy(key.ek_fsid, fsidv, key_len(fsid_type));	key.ek_mnt = exp->ex_mnt;	key.ek_dentry = exp->ex_dentry;	key.h.expiry_time = NEVER;	key.h.flags = 0;	ek = svc_expkey_lookup(&key);	if (ek)		ek = svc_expkey_update(&key,ek);	if (ek) {		cache_put(&ek->h, &svc_expkey_cache);		return 0;	}	return -ENOMEM;}/* * Find the client's export entry matching xdev/xino. */static inline struct svc_expkey *exp_get_key(svc_client *clp, dev_t dev, ino_t ino){	u32 fsidv[3];		if (old_valid_dev(dev)) {		mk_fsid(FSID_DEV, fsidv, dev, ino, 0, NULL);		return exp_find_key(clp, FSID_DEV, fsidv, NULL);	}	mk_fsid(FSID_ENCODE_DEV, fsidv, dev, ino, 0, NULL);	return exp_find_key(clp, FSID_ENCODE_DEV, fsidv, NULL);}/* * Find the client's export entry matching fsid */static inline struct svc_expkey *exp_get_fsid_key(svc_client *clp, int fsid){	u32 fsidv[2];	mk_fsid(FSID_NUM, fsidv, 0, 0, fsid, NULL);	return exp_find_key(clp, FSID_NUM, fsidv, NULL);}static svc_export *exp_get_by_name(svc_client *clp, struct vfsmount *mnt,				   struct dentry *dentry,				   struct cache_req *reqp){	struct svc_export *exp, key;	int err;		if (!clp)		return ERR_PTR(-ENOENT);	key.ex_client = clp;	key.ex_mnt = mnt;	key.ex_dentry = dentry;	exp = svc_export_lookup(&key);	if (exp == NULL)		return ERR_PTR(-ENOMEM);	err = cache_check(&svc_export_cache, &exp->h, reqp);	if (err)		return ERR_PTR(err);	return exp;}/* * Find the export entry for a given dentry. */static struct svc_export *exp_parent(svc_client *clp, struct vfsmount *mnt,				     struct dentry *dentry,				     struct cache_req *reqp){	svc_export *exp;	dget(dentry);	exp = exp_get_by_name(clp, mnt, dentry, reqp);	while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(dentry)) {		struct dentry *parent;		parent = dget_parent(dentry);		dput(dentry);		dentry = parent;		exp = exp_get_by_name(clp, mnt, dentry, reqp);	}	dput(dentry);	return exp;}/* * Hashtable locking. Write locks are placed only by user processes * wanting to modify export information. * Write locking only done in this file.  Read locking * needed externally. */static DECLARE_RWSEM(hash_sem);voidexp_readlock(void){	down_read(&hash_sem);}static inline voidexp_writelock(void){	down_write(&hash_sem);}voidexp_readunlock(void){	up_read(&hash_sem);}static inline voidexp_writeunlock(void){	up_write(&hash_sem);}static void exp_fsid_unhash(struct svc_export *exp){	struct svc_expkey *ek;	if ((exp->ex_flags & NFSEXP_FSID) == 0)		return;	ek = exp_get_fsid_key(exp->ex_client, exp->ex_fsid);	if (!IS_ERR(ek)) {		ek->h.expiry_time = get_seconds()-1;		cache_put(&ek->h, &svc_expkey_cache);	}	svc_expkey_cache.nextcheck = get_seconds();}static int exp_fsid_hash(svc_client *clp, struct svc_export *exp){	u32 fsid[2]; 	if ((exp->ex_flags & NFSEXP_FSID) == 0)		return 0;	mk_fsid(FSID_NUM, fsid, 0, 0, exp->ex_fsid, NULL);	return exp_set_key(clp, FSID_NUM, fsid, exp);}static int exp_hash(struct auth_domain *clp, struct svc_export *exp){	u32 fsid[2];	struct inode *inode = exp->ex_dentry->d_inode;	dev_t dev = inode->i_sb->s_dev;	if (old_valid_dev(dev)) {		mk_fsid(FSID_DEV, fsid, dev, inode->i_ino, 0, NULL);		return exp_set_key(clp, FSID_DEV, fsid, exp);	}	mk_fsid(FSID_ENCODE_DEV, fsid, dev, inode->i_ino, 0, NULL);	return exp_set_key(clp, FSID_ENCODE_DEV, fsid, exp);}static void exp_unhash(struct svc_export *exp){	struct svc_expkey *ek;	struct inode *inode = exp->ex_dentry->d_inode;	ek = exp_get_key(exp->ex_client, inode->i_sb->s_dev, inode->i_ino);	if (!IS_ERR(ek)) {		ek->h.expiry_time = get_seconds()-1;		cache_put(&ek->h, &svc_expkey_cache);	}	svc_expkey_cache.nextcheck = get_seconds();}	/* * Export a file system. */intexp_export(struct nfsctl_export *nxp){	svc_client	*clp;	struct svc_export	*exp = NULL;	struct svc_export	new;	struct svc_expkey	*fsid_key = NULL;	struct nameidata nd;	int		err;	/* Consistency check */	err = -EINVAL;	if (!exp_verify_string(nxp->ex_path, NFS_MAXPATHLEN) ||	    !exp_verify_string(nxp->ex_client, NFSCLNT_IDMAX))		goto out;	dprintk("exp_export called for %s:%s (%x/%ld fl %x).\n",			nxp->ex_client, nxp->ex_path,			(unsigned)nxp->ex_dev, (long)nxp->ex_ino,			nxp->ex_flags);	/* Try to lock the export table for update */	exp_writelock();	/* Look up client info */	if (!(clp = auth_domain_find(nxp->ex_client)))		goto out_unlock;	/* Look up the dentry */	err = path_lookup(nxp->ex_path, 0, &nd);	if (err)		goto out_unlock;	err = -EINVAL;	exp = exp_get_by_name(clp, nd.mnt, nd.dentry, NULL);	memset(&new, 0, sizeof(new));	/* must make sure there won't be an ex_fsid clash */	if ((nxp->ex_flags & NFSEXP_FSID) &&	    (!IS_ERR(fsid_key = exp_get_fsid_key(clp, nxp->ex_dev))) &&	    fsid_key->ek_mnt &&	    (fsid_key->ek_mnt != nd.mnt || fsid_key->ek_dentry != nd.dentry) )		goto finish;	if (!IS_ERR(exp)) {		/* just a flags/id/fsid update */		exp_fsid_unhash(exp);		exp->ex_flags    = nxp->ex_flags;		exp->ex_anon_uid = nxp->ex_anon_uid;		exp->ex_anon_gid = nxp->ex_anon_gid;		exp->ex_fsid     = nxp->ex_dev;		err = exp_fsid_hash(clp, exp);		goto finish;	}	err = check_export(nd.dentry->d_inode, nxp->ex_flags, NULL);	if (err) goto finish;	err = -ENOMEM;	dprintk("nfsd: creating export entry %p for client %p\n", exp, clp);	new.h.expiry_time = NEVER;	new.h.flags = 0;	new.ex_path = kstrdup(nxp->ex_path, GFP_KERNEL);	if (!new.ex_path)		goto finish;	new.ex_client = clp;	new.ex_mnt = nd.mnt;	new.ex_dentry = nd.dentry;	new.ex_flags = nxp->ex_flags;	new.ex_anon_uid = nxp->ex_anon_uid;	new.ex_anon_gid = nxp->ex_anon_gid;	new.ex_fsid = nxp->ex_dev;	exp = svc_export_lookup(&new);	if (exp)		exp = svc_export_update(&new, exp);	if (!exp)		goto finish;	if (exp_hash(clp, exp) ||	    exp_fsid_hash(clp, exp)) {		/* failed to create at least one index */		exp_do_unexport(exp);		cache_flush();	} else		err = 0;finish:	if (new.ex_path)		kfree(new.ex_path);	if (exp)		exp_put(exp);	if (fsid_key && !IS_ERR(fsid_key))		cache_put(&fsid_key->h, &svc_expkey_cache);	if (clp)		auth_domain_put(clp);	path_release(&nd);out_unlock:	exp_writeunlock();out:	return err;}/* * Unexport a file system. The export entry has already * been removed from the client's list of exported fs's. */static voidexp_do_unexport(svc_export *unexp){	unexp->h.expiry_time = get_seconds()-1;	svc_export_cache.nextcheck = get_seconds();	exp_unhash(unexp);	exp_fsid_unhash(unexp);}/* * unexport syscall.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -