From 5fb79f1ea048d1ffa9162f5a5e3336b9f586dada Mon Sep 17 00:00:00 2001 From: mucor Date: Fri, 23 Apr 2021 18:24:38 +0800 Subject: [PATCH] while nfs_create failed return error code and set null for vnode Change-Id: Ib99e937093336cfb16c44d0f811613d90f1b2f13 --- fs/nfs/nfs_adapter.c | 118 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/fs/nfs/nfs_adapter.c b/fs/nfs/nfs_adapter.c index fb81763..3ccb847 100644 --- a/fs/nfs/nfs_adapter.c +++ b/fs/nfs/nfs_adapter.c @@ -2075,83 +2075,85 @@ int vfs_nfs_create(struct Vnode *parent, const char *filename, int mode, struct /* Check for success */ - if (error == OK) + if (error != OK) { - /* Parse the returned data */ - - ptr = (uint32_t *)&((struct rpc_reply_create *) - nmp->nm_iobuffer)->create; + *vpp = NULL; + goto errout_with_mutex; + } + + /* Parse the returned data */ - /* Save the file handle in the file data structure */ + ptr = (uint32_t *)&((struct rpc_reply_create *) + nmp->nm_iobuffer)->create; - tmp = *ptr++; /* handle_follows */ - if (!tmp) - { - PRINTK("ERROR: no file handle follows\n"); - error = EINVAL; - goto errout_with_mutex; - } + /* Save the file handle in the file data structure */ - tmp = *ptr++; - tmp = fxdr_unsigned(uint32_t, tmp); - DEBUGASSERT(tmp <= NFSX_V3FHMAX); + tmp = *ptr++; /* handle_follows */ + if (!tmp) + { + PRINTK("ERROR: no file handle follows\n"); + error = EINVAL; + goto errout_with_mutex; + } - np->n_fhsize = (uint8_t)tmp; - (void)memcpy_s(&np->n_fhandle, tmp, ptr, tmp); - ptr += uint32_increment(tmp); + tmp = *ptr++; + tmp = fxdr_unsigned(uint32_t, tmp); + DEBUGASSERT(tmp <= NFSX_V3FHMAX); - /* Save the attributes in the file data structure */ + np->n_fhsize = (uint8_t)tmp; + (void)memcpy_s(&np->n_fhandle, tmp, ptr, tmp); + ptr += uint32_increment(tmp); - tmp = *ptr; /* handle_follows */ - if (!tmp) - { - PRINTK("WARNING: no file attributes\n"); - } - else - { - /* Initialize the file attributes */ + /* Save the attributes in the file data structure */ - nfs_attrupdate(np, (struct nfs_fattr *)ptr); - } + tmp = *ptr; /* handle_follows */ + if (!tmp) + { + PRINTK("WARNING: no file attributes\n"); + } + else + { + /* Initialize the file attributes */ - /* Any following dir_wcc data is ignored for now */ - np->n_crefs = 1; + nfs_attrupdate(np, (struct nfs_fattr *)ptr); + } - /* Attach the private data to the struct file instance */ + /* Any following dir_wcc data is ignored for now */ + np->n_crefs = 1; - /* Then insert the new instance at the head of the list in the mountpoint - * tructure. It needs to be there (1) to handle error conditions that effect - * all files, and (2) to inform the umount logic that we are busy. We - * cannot unmount the file system if this list is not empty! - */ + /* Attach the private data to the struct file instance */ - np->n_next = nmp->nm_head; - nmp->nm_head = np; + /* Then insert the new instance at the head of the list in the mountpoint + * tructure. It needs to be there (1) to handle error conditions that effect + * all files, and (2) to inform the umount logic that we are busy. We + * cannot unmount the file system if this list is not empty! + */ - np->n_flags |= (NFSNODE_OPEN | NFSNODE_MODIFIED); - np->n_name = zalloc(namelen + 1); - memcpy_s(np->n_name, (namelen + 1), filename, (namelen + 1)); + np->n_next = nmp->nm_head; + nmp->nm_head = np; - (void)VnodeAlloc(&nfs_vops, vpp); - (*vpp)->parent = parent; - (*vpp)->fop = &nfs_fops; - (*vpp)->originMount = parent->originMount; - (*vpp)->data = np; - (*vpp)->type = filetype_to_vnodetype(np->n_type); - (*vpp)->mode = type_to_mode((*vpp)->type, nmp->nm_permission); - (*vpp)->gid = nmp->nm_gid; - (*vpp)->uid = nmp->nm_uid; + np->n_flags |= (NFSNODE_OPEN | NFSNODE_MODIFIED); + np->n_name = zalloc(namelen + 1); + memcpy_s(np->n_name, (namelen + 1), filename, (namelen + 1)); - } + (void)VnodeAlloc(&nfs_vops, vpp); + (*vpp)->parent = parent; + (*vpp)->fop = &nfs_fops; + (*vpp)->originMount = parent->originMount; + (*vpp)->data = np; + (*vpp)->type = filetype_to_vnodetype(np->n_type); + (*vpp)->mode = type_to_mode((*vpp)->type, nmp->nm_permission); + (*vpp)->gid = nmp->nm_gid; + (*vpp)->uid = nmp->nm_uid; nfs_mux_release(nmp); return OK; - errout_with_mutex: - if (np) - { - free(np); - } +errout_with_mutex: + if (np) + { + free(np); + } nfs_mux_release(nmp); return -error; } -- GitLab