示例#1
0
int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
		mode_t mode)
{
	struct posix_acl *dfacl, *acl;
	int error = 0;

	dfacl = nfs3_proc_getacl(dir, ACL_TYPE_DEFAULT);
	if (IS_ERR(dfacl)) {
		error = PTR_ERR(dfacl);
		return (error == -EOPNOTSUPP) ? 0 : error;
	}
	if (!dfacl)
		return 0;
	acl = posix_acl_clone(dfacl, GFP_KERNEL);
	error = -ENOMEM;
	if (!acl)
		goto out_release_dfacl;
	error = posix_acl_create_masq(acl, &mode);
	if (error < 0)
		goto out_release_acl;
	error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?
						      dfacl : NULL);
out_release_acl:
	posix_acl_release(acl);
out_release_dfacl:
	posix_acl_release(dfacl);
	return error;
}
示例#2
0
int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
{
	struct posix_acl *alloc = NULL, *dfacl = NULL;
	int status;

	if (S_ISDIR(inode->i_mode)) {
		switch(type) {
			case ACL_TYPE_ACCESS:
				alloc = dfacl = nfs3_proc_getacl(inode,
						ACL_TYPE_DEFAULT);
				if (IS_ERR(alloc))
					goto fail;
				break;

			case ACL_TYPE_DEFAULT:
				dfacl = acl;
				alloc = acl = nfs3_proc_getacl(inode,
						ACL_TYPE_ACCESS);
				if (IS_ERR(alloc))
					goto fail;
				break;

			default:
				return -EINVAL;
		}
	} else if (type != ACL_TYPE_ACCESS)
			return -EINVAL;

	if (acl == NULL) {
		alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
		if (IS_ERR(alloc))
			goto fail;
	}
	status = nfs3_proc_setacls(inode, acl, dfacl);
	posix_acl_release(alloc);
	return status;

fail:
	return PTR_ERR(alloc);
}
示例#3
0
文件: nfs3proc.c 项目: a342604203/nfs
static int
nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
{
    struct nfs3_linkargs	arg = {
        .fromfh		= NFS_FH(inode),
        .tofh		= NFS_FH(dir),
        .toname		= name->name,
        .tolen		= name->len
    };
    struct nfs3_linkres	res;
    struct rpc_message msg = {
        .rpc_proc	= &nfs3_procedures[NFS3PROC_LINK],
        .rpc_argp	= &arg,
        .rpc_resp	= &res,
    };
    int status = -ENOMEM;

    dprintk("NFS call  link %s\n", name->name);
    res.fattr = nfs_alloc_fattr();
    res.dir_attr = nfs_alloc_fattr();
    if (res.fattr == NULL || res.dir_attr == NULL)
        goto out;

    zql_control_test(NFS_SERVER(inode));
    status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
    nfs_post_op_update_inode(dir, res.dir_attr);
    nfs_post_op_update_inode(inode, res.fattr);
out:
    nfs_free_fattr(res.dir_attr);
    nfs_free_fattr(res.fattr);
    dprintk("NFS reply link: %d\n", status);
    return status;
}

static int
nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
                  unsigned int len, struct iattr *sattr)
{
    struct nfs3_createdata *data;
    int status = -ENOMEM;

    if (len > NFS3_MAXPATHLEN)
        return -ENAMETOOLONG;

    dprintk("NFS call  symlink %pd\n", dentry);

    data = nfs3_alloc_createdata();
    if (data == NULL)
        goto out;
    data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
    data->arg.symlink.fromfh = NFS_FH(dir);
    data->arg.symlink.fromname = dentry->d_name.name;
    data->arg.symlink.fromlen = dentry->d_name.len;
    data->arg.symlink.pages = &page;
    data->arg.symlink.pathlen = len;
    data->arg.symlink.sattr = sattr;

    zql_control_test(NFS_SERVER(dir));
    status = nfs3_do_create(dir, dentry, data);

    nfs3_free_createdata(data);
out:
    dprintk("NFS reply symlink: %d\n", status);
    return status;
}

static int
nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
{
    struct posix_acl *default_acl, *acl;
    struct nfs3_createdata *data;
    int status = -ENOMEM;

    dprintk("NFS call  mkdir %pd\n", dentry);

    data = nfs3_alloc_createdata();
    if (data == NULL)
        goto out;

    status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
    if (status)
        goto out;

    data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
    data->arg.mkdir.fh = NFS_FH(dir);
    data->arg.mkdir.name = dentry->d_name.name;
    data->arg.mkdir.len = dentry->d_name.len;
    data->arg.mkdir.sattr = sattr;

    zql_control_test(NFS_SERVER(dir));
    status = nfs3_do_create(dir, dentry, data);
    if (status != 0)
        goto out_release_acls;

    status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl);

out_release_acls:
    posix_acl_release(acl);
    posix_acl_release(default_acl);
out:
    nfs3_free_createdata(data);
    dprintk("NFS reply mkdir: %d\n", status);
    return status;
}

static int
nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
{
    struct nfs_fattr	*dir_attr;
    struct nfs3_diropargs	arg = {
        .fh		= NFS_FH(dir),
        .name		= name->name,
        .len		= name->len
    };
    struct rpc_message msg = {
        .rpc_proc	= &nfs3_procedures[NFS3PROC_RMDIR],
        .rpc_argp	= &arg,
    };
    int status = -ENOMEM;

    dprintk("NFS call  rmdir %s\n", name->name);
    dir_attr = nfs_alloc_fattr();
    if (dir_attr == NULL)
        goto out;

    msg.rpc_resp = dir_attr;
    zql_control_test(NFS_SERVER(dir));
    status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
    nfs_post_op_update_inode(dir, dir_attr);
    nfs_free_fattr(dir_attr);
out:
    dprintk("NFS reply rmdir: %d\n", status);
    return status;
}

/*
 * The READDIR implementation is somewhat hackish - we pass the user buffer
 * to the encode function, which installs it in the receive iovec.
 * The decode function itself doesn't perform any decoding, it just makes
 * sure the reply is syntactically correct.
 *
 * Also note that this implementation handles both plain readdir and
 * readdirplus.
 */
static int
nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
                  u64 cookie, struct page **pages, unsigned int count, int plus)
{
    struct inode		*dir = dentry->d_inode;
    __be32			*verf = NFS_I(dir)->cookieverf;
    struct nfs3_readdirargs	arg = {
        .fh		= NFS_FH(dir),
        .cookie		= cookie,
        .verf		= {verf[0], verf[1]},
        .plus		= plus,
        .count		= count,
        .pages		= pages
    };
    struct nfs3_readdirres	res = {
        .verf		= verf,
        .plus		= plus
    };
    struct rpc_message	msg = {
        .rpc_proc	= &nfs3_procedures[NFS3PROC_READDIR],
        .rpc_argp	= &arg,
        .rpc_resp	= &res,
        .rpc_cred	= cred
    };
    int status = -ENOMEM;

    if (plus)
        msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];

    dprintk("NFS call  readdir%s %d\n",
            plus? "plus" : "", (unsigned int) cookie);

    res.dir_attr = nfs_alloc_fattr();
    if (res.dir_attr == NULL)
        goto out;

    zql_control_test(NFS_SERVER(dir));
    status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);

    nfs_invalidate_atime(dir);
    nfs_refresh_inode(dir, res.dir_attr);

    nfs_free_fattr(res.dir_attr);
out:
    dprintk("NFS reply readdir%s: %d\n",
            plus? "plus" : "", status);
    return status;
}

static int
nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
                dev_t rdev)
{
    struct posix_acl *default_acl, *acl;
    struct nfs3_createdata *data;
    int status = -ENOMEM;

    dprintk("NFS call  mknod %pd %u:%u\n", dentry,
            MAJOR(rdev), MINOR(rdev));

    data = nfs3_alloc_createdata();
    if (data == NULL)
        goto out;

    status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
    if (status)
        goto out;

    data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
    data->arg.mknod.fh = NFS_FH(dir);
    data->arg.mknod.name = dentry->d_name.name;
    data->arg.mknod.len = dentry->d_name.len;
    data->arg.mknod.sattr = sattr;
    data->arg.mknod.rdev = rdev;

    switch (sattr->ia_mode & S_IFMT) {
    case S_IFBLK:
        data->arg.mknod.type = NF3BLK;
        break;
    case S_IFCHR:
        data->arg.mknod.type = NF3CHR;
        break;
    case S_IFIFO:
        data->arg.mknod.type = NF3FIFO;
        break;
    case S_IFSOCK:
        data->arg.mknod.type = NF3SOCK;
        break;
    default:
        status = -EINVAL;
        goto out;
    }

    zql_control_test(NFS_SERVER(dir));
    status = nfs3_do_create(dir, dentry, data);
    if (status != 0)
        goto out_release_acls;

    status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl);

out_release_acls:
    posix_acl_release(acl);
    posix_acl_release(default_acl);
out:
    nfs3_free_createdata(data);
    dprintk("NFS reply mknod: %d\n", status);
    return status;
}

static int
nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
                 struct nfs_fsstat *stat)
{
    struct rpc_message msg = {
        .rpc_proc	= &nfs3_procedures[NFS3PROC_FSSTAT],
        .rpc_argp	= fhandle,
        .rpc_resp	= stat,
    };
    int	status;

    dprintk("NFS call  fsstat\n");
    nfs_fattr_init(stat->fattr);
    zql_control_test(server);
    status = rpc_call_sync(server->client, &msg, 0);
    dprintk("NFS reply fsstat: %d\n", status);
    return status;
}

static int
do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
               struct nfs_fsinfo *info)
{
    struct rpc_message msg = {
        .rpc_proc	= &nfs3_procedures[NFS3PROC_FSINFO],
        .rpc_argp	= fhandle,
        .rpc_resp	= info,
    };
    int	status;

    dprintk("NFS call  fsinfo\n");
    nfs_fattr_init(info->fattr);
    status = rpc_call_sync(client, &msg, 0);
    dprintk("NFS reply fsinfo: %d\n", status);
    return status;
}

/*
 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
 * nfs_create_server
 */
static int
nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
                 struct nfs_fsinfo *info)
{
    int	status;

    zql_control_test(server);
    status = do_proc_fsinfo(server->client, fhandle, info);
    if (status && server->nfs_client->cl_rpcclient != server->client)
        status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
    return status;
}
示例#4
0
文件: nfs3proc.c 项目: a342604203/nfs
/*
 * Create a regular file.
 */
static int
nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
                 int flags)
{
    struct posix_acl *default_acl, *acl;
    struct nfs3_createdata *data;
    int status = -ENOMEM;

    dprintk("NFS call  create %pd\n", dentry);

    data = nfs3_alloc_createdata();
    if (data == NULL)
        goto out;

    data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
    data->arg.create.fh = NFS_FH(dir);
    data->arg.create.name = dentry->d_name.name;
    data->arg.create.len = dentry->d_name.len;
    data->arg.create.sattr = sattr;

    data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
    if (flags & O_EXCL) {
        data->arg.create.createmode  = NFS3_CREATE_EXCLUSIVE;
        data->arg.create.verifier[0] = cpu_to_be32(jiffies);
        data->arg.create.verifier[1] = cpu_to_be32(current->pid);
    }

    status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
    if (status)
        goto out;

    zql_control_test(NFS_SERVER(dir));
    for (;;) {
        status = nfs3_do_create(dir, dentry, data);

        if (status != -ENOTSUPP)
            break;
        /* If the server doesn't support the exclusive creation
         * semantics, try again with simple 'guarded' mode. */
        switch (data->arg.create.createmode) {
        case NFS3_CREATE_EXCLUSIVE:
            data->arg.create.createmode = NFS3_CREATE_GUARDED;
            break;

        case NFS3_CREATE_GUARDED:
            data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
            break;

        case NFS3_CREATE_UNCHECKED:
            goto out;
        }
        nfs_fattr_init(data->res.dir_attr);
        nfs_fattr_init(data->res.fattr);
    }

    if (status != 0)
        goto out_release_acls;

    /* When we created the file with exclusive semantics, make
     * sure we set the attributes afterwards. */
    if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
        dprintk("NFS call  setattr (post-create)\n");

        if (!(sattr->ia_valid & ATTR_ATIME_SET))
            sattr->ia_valid |= ATTR_ATIME;
        if (!(sattr->ia_valid & ATTR_MTIME_SET))
            sattr->ia_valid |= ATTR_MTIME;

        /* Note: we could use a guarded setattr here, but I'm
         * not sure this buys us anything (and I'd have
         * to revamp the NFSv3 XDR code) */
        status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
        nfs_post_op_update_inode(dentry->d_inode, data->res.fattr);
        dprintk("NFS reply setattr (post-create): %d\n", status);
        if (status != 0)
            goto out_release_acls;
    }

    status = nfs3_proc_setacls(dentry->d_inode, acl, default_acl);

out_release_acls:
    posix_acl_release(acl);
    posix_acl_release(default_acl);
out:
    nfs3_free_createdata(data);
    dprintk("NFS reply create: %d\n", status);
    return status;
}