예제 #1
0
int v9fs_file_open(struct inode *inode, struct file *file)
{
	int err;
	struct v9fs_session_info *v9ses;
	struct p9_fid *fid;
	int omode;

	P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p \n", inode, file);
	v9ses = v9fs_inode2v9ses(inode);
	omode = v9fs_uflags2omode(file->f_flags, v9fs_extended(v9ses));
	fid = file->private_data;
	if (!fid) {
		fid = v9fs_fid_clone(file->f_path.dentry);
		if (IS_ERR(fid))
			return PTR_ERR(fid);

		err = p9_client_open(fid, omode);
		if (err < 0) {
			p9_client_clunk(fid);
			return err;
		}
		if (omode & P9_OTRUNC) {
			i_size_write(inode, 0);
			inode->i_blocks = 0;
		}
		if ((file->f_flags & O_APPEND) && (!v9fs_extended(v9ses)))
			generic_file_llseek(file, 0, SEEK_END);
	}

	file->private_data = fid;
	if ((fid->qid.version) && (v9ses->cache)) {
		P9_DPRINTK(P9_DEBUG_VFS, "cached");
		/* enable cached file options */
		if(file->f_op == &v9fs_file_operations)
			file->f_op = &v9fs_cached_file_operations;

#ifdef CONFIG_9P_FSCACHE
		v9fs_cache_inode_set_cookie(inode, file);
#endif
	}

	return 0;
}
예제 #2
0
파일: v9fs.c 프로젝트: 274914765/C
struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
          const char *dev_name, char *data)
{
    int retval = -EINVAL;
    struct p9_fid *fid;
    int rc;

    v9ses->uname = __getname();
    if (!v9ses->uname)
        return ERR_PTR(-ENOMEM);

    v9ses->aname = __getname();
    if (!v9ses->aname) {
        __putname(v9ses->uname);
        return ERR_PTR(-ENOMEM);
    }

    v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER;
    strcpy(v9ses->uname, V9FS_DEFUSER);
    strcpy(v9ses->aname, V9FS_DEFANAME);
    v9ses->uid = ~0;
    v9ses->dfltuid = V9FS_DEFUID;
    v9ses->dfltgid = V9FS_DEFGID;
    if (data) {
        v9ses->options = kstrdup(data, GFP_KERNEL);
        if (!v9ses->options) {
            P9_DPRINTK(P9_DEBUG_ERROR,
               "failed to allocate copy of option string\n");
            retval = -ENOMEM;
            goto error;
        }
    }

    rc = v9fs_parse_options(v9ses);
    if (rc < 0) {
        retval = rc;
        goto error;
    }

    v9ses->clnt = p9_client_create(dev_name, v9ses->options);

    if (IS_ERR(v9ses->clnt)) {
        retval = PTR_ERR(v9ses->clnt);
        v9ses->clnt = NULL;
        P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
        goto error;
    }

    if (!v9ses->clnt->dotu)
        v9ses->flags &= ~V9FS_EXTENDED;

    v9ses->maxdata = v9ses->clnt->msize;

    /* for legacy mode, fall back to V9FS_ACCESS_ANY */
    if (!v9fs_extended(v9ses) &&
        ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {

        v9ses->flags &= ~V9FS_ACCESS_MASK;
        v9ses->flags |= V9FS_ACCESS_ANY;
        v9ses->uid = ~0;
    }

    fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0,
                            v9ses->aname);
    if (IS_ERR(fid)) {
        retval = PTR_ERR(fid);
        fid = NULL;
        P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
        goto error;
    }

    if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
        fid->uid = v9ses->uid;
    else
        fid->uid = ~0;

    return fid;

error:
    return ERR_PTR(retval);
}