diff options
Diffstat (limited to 'xlators/nfs/server/src/nfs3-helpers.c')
-rw-r--r-- | xlators/nfs/server/src/nfs3-helpers.c | 2394 |
1 files changed, 1676 insertions, 718 deletions
diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c index 2070d196add..5b0daed8253 100644 --- a/xlators/nfs/server/src/nfs3-helpers.c +++ b/xlators/nfs/server/src/nfs3-helpers.c @@ -1617,700 +1617,1804 @@ err: } -/* When remove a file, we need to unref the cached fd for an inode but this - * needs to happen only when the file was in fact opened. However, it is - * possible that fd_lookup on a file returns an fd because the file was in - * process of being created(which also returns an fd) but since this fd was not - * opened through this path, in the NFS3 remove path, we'll end up removing the - * reference that belongs to someone else. That means, nfs3 remove path should - * not unref unless it is sure that the file was cached open also. If it was, - * only then perform the fd_unref, else not. - * - * We determine that using a flag in the inode context. - */ -int -nfs3_set_inode_opened (xlator_t *nfsxl, inode_t *inode) +void +nfs3_stat_to_errstr (uint32_t xid, char *op, nfsstat3 stat, int pstat, + char *errstr) { - if ((!nfsxl) || (!inode)) - return -1; + if ((!op) || (!errstr)) + return; + + sprintf (errstr, "XID: %x, %s: NFS: %d(%s), POSIX: %d(%s)", xid, op, + stat, nfsstat3_strerror (stat), pstat, strerror (pstat)); +} - inode_ctx_put (inode, nfsxl, GF_NFS3_FD_CACHED); +void +nfs3_log_common_call (uint32_t xid, char *op, struct nfs3_fh *fh) +{ + char fhstr[1024]; - return 0; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + + nfs3_fh_to_str (fh, fhstr); + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s", xid, op, + fhstr); } -/* Returns 1 if inode was cached open, otherwise 0 */ -int -nfs3_cached_inode_opened (xlator_t *nfsxl, inode_t *inode) +void +nfs3_log_fh_entry_call (uint32_t xid, char *op, struct nfs3_fh *fh, + char *name) { - int ret = -1; - uint64_t cflag = 0; + char fhstr[1024]; - if ((!nfsxl) || (!inode)) - return -1; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, name: %s", xid, + op, fhstr, name); +} - ret = inode_ctx_get (inode, nfsxl, &cflag); - if (ret == -1) - ret = 0; - else if (cflag == GF_NFS3_FD_CACHED) - ret = 1; - return ret; +void +nfs3_log_rename_call (uint32_t xid, struct nfs3_fh *src, char *sname, + struct nfs3_fh *dst, char *dname) +{ + char sfhstr[1024]; + char dfhstr[1024]; + + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (src, sfhstr); + nfs3_fh_to_str (dst, dfhstr); + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, RENAME: args: Src: %s, " + "name: %s, Dst: %s, name: %s", xid, sfhstr, sname, dfhstr, + dname); } -int32_t -nfs3_dir_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) + +void +nfs3_log_create_call (uint32_t xid, struct nfs3_fh *fh, char *name, + createmode3 mode) { - nfs3_call_state_t *cs = NULL; + char fhstr[1024]; + char *modestr = NULL; + char exclmode[] = "EXCLUSIVE"; + char unchkd[] = "UNCHECKED"; + char guarded[] = "GUARDED"; - cs = frame->local; - if (op_ret == -1) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Dir open failed path %s err %s" - , cs->resolvedloc.path, strerror (op_errno)); - cs->resolve_ret = -1; - cs->resolve_errno = op_errno; - nfs3_call_resume (cs); - goto err; - } + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); + if (mode == EXCLUSIVE) + modestr = exclmode; + else if (mode == GUARDED) + modestr = guarded; + else + modestr = unchkd; - cs->fd = fd; /* Gets unrefd when the call state is wiped. */ - nfs3_set_inode_opened (cs->nfsx, cs->resolvedloc.inode); - gf_log (GF_NFS3, GF_LOG_TRACE, "FD_REF: %d", fd->refcount); - nfs3_call_resume (cs); -err: - return 0; + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, CREATE: args: %s, name: %s," + " mode: %s", xid, fhstr, name, modestr); } -int -__nfs3_dir_open_and_resume (nfs3_call_state_t *cs) +void +nfs3_log_mknod_call (uint32_t xid, struct nfs3_fh *fh, char *name, int type) { - nfs_user_t nfu = {0, }; - int ret = -EFAULT; + char fhstr[1024]; + char *modestr = NULL; + char chr[] = "CHAR"; + char blk[] = "BLK"; + char sock[] = "SOCK"; + char fifo[] = "FIFO"; - if (!cs) - return ret; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); + if (type == NF3CHR) + modestr = chr; + else if (type == NF3BLK) + modestr = blk; + else if (type == NF3SOCK) + modestr = sock; + else + modestr = fifo; - nfs_user_root_create (&nfu); - ret = nfs_opendir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_dir_open_cbk, cs); - return ret; + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, MKNOD: args: %s, name: %s," + " type: %s", xid, fhstr, name, modestr); } -int -nfs3_dir_open_and_resume (nfs3_call_state_t *cs, nfs3_resume_fn_t resume) + +void +nfs3_log_symlink_call (uint32_t xid, struct nfs3_fh *fh, char *name, char *tgt) { - fd_t *fd = NULL; - int ret = -EFAULT; + char fhstr[1024]; - if ((!cs)) - return ret; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, SYMLINK: args: %s, name: %s," + " target: %s", xid, fhstr, name, tgt); +} - cs->resume_fn = resume; - gf_log (GF_NFS3, GF_LOG_TRACE, "Opening: %s", cs->resolvedloc.path); - fd = fd_lookup (cs->resolvedloc.inode, 0); - if (fd) { - gf_log (GF_NFS3, GF_LOG_TRACE, "fd found in state: ref: %d", - fd->refcount); - cs->fd = fd; /* Gets unrefd when the call state is wiped. */ - cs->resolve_ret = 0; - nfs3_call_resume (cs); - ret = 0; - goto err; - } - ret = __nfs3_dir_open_and_resume (cs); +void +nfs3_log_link_call (uint32_t xid, struct nfs3_fh *fh, char *name, + struct nfs3_fh *tgt) +{ + char dfhstr[1024]; + char tfhstr[1024]; -err: - return ret; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, dfhstr); + nfs3_fh_to_str (tgt, tfhstr); + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, LINK: args: %s, name: %s," + " target: %s", xid, dfhstr, name, tfhstr); } -int -nfs3_flush_call_state (nfs3_call_state_t *cs, fd_t *openedfd, - int32_t call_resume) +void +nfs3_log_rw_call (uint32_t xid, char *op, struct nfs3_fh *fh, offset3 offt, + count3 count, int stablewrite) { - if ((!cs)) - return -1; + char fhstr[1024]; - gf_log (GF_NFS3, GF_LOG_TRACE, "Calling resume"); - if (openedfd) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Opening uncached fd done: %d", - openedfd->refcount); - cs->fd = fd_ref (openedfd); - /* Set resove_ret to 0 so that the error checking in the resume - * callback results in a successful read reply when the fd was - * opened. If the fd opening failed, the resolve_ret is already - * set to -1 in nfs3_file_open_cbk, so that will result in an - * error being returned to the nfs client' read request. - */ - cs->resolve_ret = 0; - } - list_del (&cs->openwait_q); - if (call_resume) - nfs3_call_resume (cs); + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); + if (stablewrite == -1) + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, offset:" + " %"PRIu64", count: %"PRIu32, xid, op, fhstr, offt, + count); + else + gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, offset:" + " %"PRIu64", count: %"PRIu32", %s", xid, op, fhstr, + offt, count, + (stablewrite == UNSTABLE)?"UNSTABLE":"STABLE"); - return 0; } int -nfs3_flush_inode_queue (struct inode_op_queue *inode_q, fd_t *openedfd, - int32_t call_resume) -{ - nfs3_call_state_t *cstmp = NULL; - nfs3_call_state_t *cs = NULL; +nfs3_getattr_loglevel (nfsstat3 stat) { - if (!inode_q) - return -1; + int ll = GF_LOG_DEBUG; - list_for_each_entry_safe (cs, cstmp, &inode_q->opq, openwait_q) - nfs3_flush_call_state (cs, openedfd, call_resume); + switch (stat) { - return 0; + case NFS3ERR_PERM: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ACCES: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } int -nfs3_flush_open_wait_call_states (nfs3_call_state_t *cs, fd_t *openedfd) -{ - struct inode_op_queue *inode_q = NULL; - uint64_t ctxaddr = 0; - int ret = 0; +nfs3_setattr_loglevel (nfsstat3 stat) { - if (!cs) - return -1; + int ll = GF_LOG_DEBUG; - gf_log (GF_NFS3, GF_LOG_TRACE, "Flushing call state"); - ret = inode_ctx_get (cs->resolvedloc.inode, cs->nfsx, &ctxaddr); - if (ret == -1) { - gf_log (GF_NFS3, GF_LOG_TRACE, "No inode queue present"); - goto out; - } + switch (stat) { - inode_q = (struct inode_op_queue *)(long)ctxaddr; - if (!inode_q) - goto out; + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; - pthread_mutex_lock (&inode_q->qlock); - { - nfs3_flush_inode_queue (inode_q, openedfd, 1); + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - pthread_mutex_unlock (&inode_q->qlock); -out: - return 0; + return ll; } int -__nfs3_fdcache_update_entry (struct nfs3_state *nfs3, fd_t *fd) -{ - uint64_t ctxaddr = 0; - struct nfs3_fd_entry *fde = NULL; +nfs3_lookup_loglevel (nfsstat3 stat) { - if ((!nfs3) || (!fd)) - return -1; + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_PERM: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ACCES: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; - gf_log (GF_NFS3, GF_LOG_TRACE, "Updating fd: 0x%lx", (long int)fd); - fd_ctx_get (fd, nfs3->nfsx, &ctxaddr); - fde = (struct nfs3_fd_entry *)(long)ctxaddr; - if (fde) { - list_del (&fde->list); - list_add_tail (&fde->list, &nfs3->fdlru); + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - return 0; + return ll; } int -nfs3_fdcache_update (struct nfs3_state *nfs3, fd_t *fd) -{ - if ((!nfs3) || (!fd)) - return -1; +nfs3_access_loglevel (nfsstat3 stat) { + + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; - LOCK (&nfs3->fdlrulock); - { - __nfs3_fdcache_update_entry (nfs3, fd); + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - UNLOCK (&nfs3->fdlrulock); - return 0; + return ll; } int -__nfs3_fdcache_remove_entry (struct nfs3_state *nfs3, struct nfs3_fd_entry *fde) -{ - if ((!fde) || (!nfs3)) - return 0; +nfs3_readlink_loglevel (nfsstat3 stat) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Removing fd: 0x%lx: %d", - (long int)fde->cachedfd, fde->cachedfd->refcount); - list_del (&fde->list); - fd_ctx_del (fde->cachedfd, nfs3->nfsx, NULL); - fd_unref (fde->cachedfd); - GF_FREE (fde); - --nfs3->fdcount; + int ll = GF_LOG_DEBUG; - return 0; -} + switch (stat) { + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; +} int -nfs3_fdcache_remove (struct nfs3_state *nfs3, fd_t *fd) -{ - struct nfs3_fd_entry *fde = NULL; - uint64_t ctxaddr = 0; +nfs3_read_loglevel (nfsstat3 stat) { - if ((!nfs3) || (!fd)) - return -1; + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; - LOCK (&nfs3->fdlrulock); - { - fd_ctx_get (fd, nfs3->nfsx, &ctxaddr); - fde = (struct nfs3_fd_entry *)(long)ctxaddr; - __nfs3_fdcache_remove_entry (nfs3, fde); + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - UNLOCK (&nfs3->fdlrulock); - return 0; + return ll; } int -__nfs3_fdcache_replace (struct nfs3_state *nfs3) -{ - struct nfs3_fd_entry *fde = NULL; - struct nfs3_fd_entry *tmp = NULL; +nfs3_write_loglevel (nfsstat3 stat) { - if (!nfs3) - return -1; + int ll = GF_LOG_DEBUG; - if (nfs3->fdcount <= GF_NFS3_FDCACHE_SIZE) - return 0; + switch (stat) { - list_for_each_entry_safe (fde, tmp, &nfs3->fdlru, list) + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; break; - __nfs3_fdcache_remove_entry (nfs3, fde); + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; - return 0; -} + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; -int -nfs3_fdcache_add (struct nfs3_state *nfs3, fd_t *fd) -{ - struct nfs3_fd_entry *fde = NULL; - int ret = -1; + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; - if ((!nfs3) || (!fd)) - return -1; + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; - fde = GF_CALLOC (1, sizeof (*fd), gf_nfs_mt_nfs3_fd_entry); - if (!fde) { - gf_log (GF_NFS3, GF_LOG_ERROR, "fd entry allocation failed"); - goto out; - } + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; - /* Already refd by caller. */ - fde->cachedfd = fd; - INIT_LIST_HEAD (&fde->list); - - LOCK (&nfs3->fdlrulock); - { - gf_log (GF_NFS3, GF_LOG_TRACE, "Adding fd: 0x%lx", - (long int) fd); - fd_ctx_set (fd, nfs3->nfsx, (uintptr_t)fde); - fd_bind (fd); - list_add_tail (&fde->list, &nfs3->fdlru); - ++nfs3->fdcount; - __nfs3_fdcache_replace (nfs3); + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - UNLOCK (&nfs3->fdlrulock); -out: - return ret; + return ll; } -int32_t -nfs3_file_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - nfs3_call_state_t *cs = NULL; - struct nfs3_state *nfs3 = NULL; +int +nfs3_create_loglevel (nfsstat3 stat) { - cs = frame->local; - if (op_ret == -1) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Opening uncached fd failed: " - "%s", strerror(op_errno)); - cs->resolve_ret = -1; - cs->resolve_errno = op_errno; - fd = NULL; - } else { - gf_log (GF_NFS3, GF_LOG_TRACE, "Opening uncached fd done: %d", - fd->refcount); + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - nfs3 = rpcsvc_request_program_private (cs->req); - /* Call states are flushed even when the opening of the file failed. - * This allows returning an error for each one of the file io requests - * that are currently queued waiting for the open to succeed. - */ - nfs3_flush_open_wait_call_states (cs, fd); - if (fd) - nfs3_fdcache_add (nfs3, fd); - return 0; + return ll; } -struct inode_op_queue * -__nfs3_get_inode_queue (nfs3_call_state_t *cs) -{ - struct inode_op_queue *inode_q = NULL; - int ret = -1; - uint64_t ctxaddr = 0; +int +nfs3_mkdir_loglevel (nfsstat3 stat) { - ret = __inode_ctx_get (cs->resolvedloc.inode, cs->nfsx, &ctxaddr); - if (ret == 0) { - inode_q = (struct inode_op_queue *)(long)ctxaddr; - gf_log (GF_NFS3, GF_LOG_TRACE, "Inode queue already inited"); - goto err; - } + int ll = GF_LOG_DEBUG; - inode_q = GF_CALLOC (1, sizeof (*inode_q), gf_nfs_mt_inode_q); - if (!inode_q) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Memory allocation failed"); - goto err; - } + switch (stat) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Initing inode queue"); - INIT_LIST_HEAD (&inode_q->opq); - pthread_mutex_init (&inode_q->qlock, NULL); - __inode_ctx_put (cs->resolvedloc.inode, cs->nfsx, (uintptr_t)inode_q); + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; -err: - return inode_q; -} + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; -struct inode_op_queue * -nfs3_get_inode_queue (nfs3_call_state_t *cs) -{ - struct inode_op_queue *inode_q = NULL; + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; - LOCK (&cs->resolvedloc.inode->lock); - { - inode_q = __nfs3_get_inode_queue (cs); + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - UNLOCK (&cs->resolvedloc.inode->lock); - return inode_q; + return ll; } -#define GF_NFS3_FD_OPEN_INPROGRESS 1 -#define GF_NFS3_FD_NEEDS_OPEN 0 +int +nfs3_symlink_loglevel (nfsstat3 stat) { + int ll = GF_LOG_DEBUG; -int -__nfs3_queue_call_state (struct inode_op_queue *inode_q, nfs3_call_state_t *cs) -{ - int ret = -1; + switch (stat) { - if (!inode_q) - goto err; + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; - pthread_mutex_lock (&inode_q->qlock); - { - if (list_empty (&inode_q->opq)) { - gf_log (GF_NFS3, GF_LOG_TRACE, "First call in queue"); - ret = GF_NFS3_FD_NEEDS_OPEN; - } else - ret = GF_NFS3_FD_OPEN_INPROGRESS; + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; - gf_log (GF_NFS3, GF_LOG_TRACE, "Queueing call state"); - list_add_tail (&cs->openwait_q, &inode_q->opq); + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - pthread_mutex_unlock (&inode_q->qlock); -err: - return ret; + return ll; } -/* Returns GF_NFS3_FD_NEEDS_OPEN if the current call is the first one to be - * queued. If so, the caller will need to send the open fop. If this is a - * non-first call to be queued, it means the fd opening is in progress and - * GF_NFS3_FD_OPEN_INPROGRESS is returned. - * - * Returns -1 on error. - */ int -nfs3_queue_call_state (nfs3_call_state_t *cs) -{ - struct inode_op_queue *inode_q = NULL; - int ret = -1; +nfs3_mknod_loglevel (nfsstat3 stat) { - inode_q = nfs3_get_inode_queue (cs); - if (!inode_q) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to get inode op queue"); - goto err; + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - ret = __nfs3_queue_call_state (inode_q, cs); + return ll; +} -err: - return ret; +int +nfs3_remove_loglevel (nfsstat3 stat) { + + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } int -__nfs3_file_open_and_resume (nfs3_call_state_t *cs) -{ - nfs_user_t nfu = {0, }; - int ret = -EFAULT; +nfs3_rmdir_loglevel (nfsstat3 stat) { - if (!cs) - return ret; + int ll = GF_LOG_DEBUG; - ret = nfs3_queue_call_state (cs); - if (ret == -1) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Error queueing call state"); - ret = -EFAULT; - goto out; - } else if (ret == GF_NFS3_FD_OPEN_INPROGRESS) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Open in progress. Will wait."); - ret = 0; - goto out; + switch (stat) { + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; } - nfs_user_root_create (&nfu); - gf_log (GF_NFS3, GF_LOG_TRACE, "Opening uncached fd"); - ret = nfs_open (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, O_RDWR, - nfs3_file_open_cbk, cs); -out: - return ret; + return ll; } -fd_t * -nfs3_fdcache_getfd (struct nfs3_state *nfs3, inode_t *inode) -{ - fd_t *fd = NULL; +int +nfs3_rename_loglevel (nfsstat3 stat) { - if ((!nfs3) || (!inode)) - return NULL; + int ll = GF_LOG_DEBUG; - fd = fd_lookup (inode, 0); - if (fd) { - /* Already refd by fd_lookup, so no need to ref again. */ - gf_log (GF_NFS3, GF_LOG_TRACE, "fd found in state: %d", - fd->refcount); - nfs3_fdcache_update (nfs3, fd); - } else - gf_log (GF_NFS3, GF_LOG_TRACE, "fd not found in state"); + switch (stat) { - return fd; -} + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; -int -nfs3_file_open_and_resume (nfs3_call_state_t *cs, nfs3_resume_fn_t resume) -{ - fd_t *fd = NULL; - int ret = -EFAULT; + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; - if (!cs) - return ret; + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; - cs->resume_fn = resume; - gf_log (GF_NFS3, GF_LOG_TRACE, "Opening: %s", cs->resolvedloc.path); - fd = nfs3_fdcache_getfd (cs->nfs3state, cs->resolvedloc.inode); - if (fd) { - cs->fd = fd; /* Gets unrefd when the call state is wiped. */ - cs->resolve_ret = 0; - nfs3_call_resume (cs); - ret = 0; - goto err; - } + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; - ret = __nfs3_file_open_and_resume (cs); + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; -err: - return ret; -} + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; -void -nfs3_stat_to_errstr (uint32_t xid, char *op, nfsstat3 stat, int pstat, - char *errstr) -{ - if ((!op) || (!errstr)) - return; + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; - sprintf (errstr, "XID: %x, %s: NFS: %d(%s), POSIX: %d(%s)", xid, op, - stat, nfsstat3_strerror (stat), pstat, strerror (pstat)); -} + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; -void -nfs3_log_common_call (uint32_t xid, char *op, struct nfs3_fh *fh) -{ - char fhstr[1024]; + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; - nfs3_fh_to_str (fh, fhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s", xid, op, - fhstr); -} + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; -void -nfs3_log_fh_entry_call (uint32_t xid, char *op, struct nfs3_fh *fh, - char *name) -{ - char fhstr[1024]; + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; - nfs3_fh_to_str (fh, fhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, name: %s", xid, - op, fhstr, name); + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } -void -nfs3_log_rename_call (uint32_t xid, struct nfs3_fh *src, char *sname, - struct nfs3_fh *dst, char *dname) -{ - char sfhstr[1024]; - char dfhstr[1024]; +int +nfs3_link_loglevel (nfsstat3 stat) { - nfs3_fh_to_str (src, sfhstr); - nfs3_fh_to_str (dst, dfhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, RENAME: args: Src: %s, " - "name: %s, Dst: %s, name: %s", xid, sfhstr, sname, dfhstr, - dname); -} + int ll = GF_LOG_DEBUG; + switch (stat) { + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; -void -nfs3_log_create_call (uint32_t xid, struct nfs3_fh *fh, char *name, - createmode3 mode) -{ - char fhstr[1024]; - char *modestr = NULL; - char exclmode[] = "EXCLUSIVE"; - char unchkd[] = "UNCHECKED"; - char guarded[] = "GUARDED"; + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; - nfs3_fh_to_str (fh, fhstr); - if (mode == EXCLUSIVE) - modestr = exclmode; - else if (mode == GUARDED) - modestr = guarded; - else - modestr = unchkd; + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, CREATE: args: %s, name: %s," - " mode: %s", xid, fhstr, name, modestr); -} + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; -void -nfs3_log_mknod_call (uint32_t xid, struct nfs3_fh *fh, char *name, int type) -{ - char fhstr[1024]; - char *modestr = NULL; - char chr[] = "CHAR"; - char blk[] = "BLK"; - char sock[] = "SOCK"; - char fifo[] = "FIFO"; + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; - nfs3_fh_to_str (fh, fhstr); - if (type == NF3CHR) - modestr = chr; - else if (type == NF3BLK) - modestr = blk; - else if (type == NF3SOCK) - modestr = sock; - else - modestr = fifo; + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, MKNOD: args: %s, name: %s," - " type: %s", xid, fhstr, name, modestr); -} + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; -void -nfs3_log_symlink_call (uint32_t xid, struct nfs3_fh *fh, char *name, char *tgt) -{ - char fhstr[1024]; + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; - nfs3_fh_to_str (fh, fhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, SYMLINK: args: %s, name: %s," - " target: %s", xid, fhstr, name, tgt); + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } -void -nfs3_log_link_call (uint32_t xid, struct nfs3_fh *fh, char *name, - struct nfs3_fh *tgt) -{ - char dfhstr[1024]; - char tfhstr[1024]; +int +nfs3_readdir_loglevel (nfsstat3 stat) { - nfs3_fh_to_str (fh, dfhstr); - nfs3_fh_to_str (tgt, tfhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, LINK: args: %s, name: %s," - " target: %s", xid, dfhstr, name, tfhstr); + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } -void -nfs3_log_rw_call (uint32_t xid, char *op, struct nfs3_fh *fh, offset3 offt, - count3 count, int stablewrite) -{ - char fhstr[1024]; +int +nfs3_fsstat_loglevel (nfsstat3 stat) { - nfs3_fh_to_str (fh, fhstr); - if (stablewrite == -1) - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, offset:" - " %"PRIu64", count: %"PRIu32, xid, op, fhstr, offt, - count); - else - gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, offset:" - " %"PRIu64", count: %"PRIu32", %s", xid, op, fhstr, - offt, count, - (stablewrite == UNSTABLE)?"UNSTABLE":"STABLE"); + int ll = GF_LOG_DEBUG; + + switch (stat) { + + case NFS3ERR_PERM: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOENT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ACCES: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_EXIST: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_XDEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NODEV: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_IO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NXIO: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ISDIR: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_INVAL: + ll = GF_LOG_WARNING; + break; + case NFS3ERR_NOSPC: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_ROFS: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_FBIG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_MLINK: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NAMETOOLONG: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTEMPTY: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_SERVERFAULT: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_NOTSUPP: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_BADHANDLE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_STALE: + ll = GF_LOG_WARNING; + break; + + case NFS3ERR_DQUOT: + ll = GF_LOG_WARNING; + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; } +struct nfs3op_str { + int op; + char str[100]; +}; + +struct nfs3op_str nfs3op_strings[] = { + { NFS3_NULL, "NULL"}, + { NFS3_GETATTR, "GETATTR"}, + { NFS3_SETATTR, "SETATTR"}, + { NFS3_LOOKUP, "LOOKUP"}, + { NFS3_ACCESS, "ACCESS"}, + { NFS3_READLINK, "READLINK"}, + { NFS3_READ, "READ"}, + { NFS3_WRITE, "WRITE"}, + { NFS3_CREATE, "CREATE"}, + { NFS3_MKDIR, "MKDIR"}, + { NFS3_SYMLINK, "SYMLINK"}, + { NFS3_MKNOD, "MKNOD"}, + { NFS3_REMOVE, "REMOVE"}, + { NFS3_RMDIR, "RMDIR"}, + { NFS3_RENAME, "RENAME"}, + { NFS3_LINK, "LINK"}, + { NFS3_READDIR, "READDIR"}, + { NFS3_READDIRP, "READDIRP"}, + { NFS3_FSSTAT, "FSSTAT"}, + { NFS3_FSINFO, "FSINFO"}, + { NFS3_PATHCONF, "PATHCONF"}, + { NFS3_COMMIT, "COMMIT"}, +}; + +int +nfs3_loglevel (int nfs_op, nfsstat3 stat) { + + int ll = GF_LOG_DEBUG; + + switch (nfs_op) { + case NFS3_GETATTR: + ll = nfs3_getattr_loglevel (stat); + break; + + case NFS3_SETATTR: + ll = nfs3_setattr_loglevel (stat); + break; + + case NFS3_LOOKUP: + ll = nfs3_lookup_loglevel (stat); + break; + + case NFS3_ACCESS: + ll = nfs3_access_loglevel (stat); + break; + + case NFS3_READLINK: + ll = nfs3_readlink_loglevel (stat); + break; + + case NFS3_READ: + ll = nfs3_read_loglevel (stat); + break; + + case NFS3_WRITE: + ll = nfs3_write_loglevel (stat); + break; + + case NFS3_CREATE: + ll = nfs3_create_loglevel (stat); + break; + + case NFS3_MKDIR: + ll = nfs3_mkdir_loglevel (stat); + break; + + case NFS3_SYMLINK: + ll = nfs3_symlink_loglevel (stat); + break; + + case NFS3_MKNOD: + ll = nfs3_mknod_loglevel (stat); + break; + + case NFS3_REMOVE: + ll = nfs3_remove_loglevel (stat); + break; + + case NFS3_RMDIR: + ll = nfs3_rmdir_loglevel (stat); + break; + + case NFS3_RENAME: + ll = nfs3_rename_loglevel (stat); + break; + + case NFS3_LINK: + ll = nfs3_link_loglevel (stat); + break; + + case NFS3_READDIR: + ll = nfs3_readdir_loglevel (stat); + break; + + case NFS3_READDIRP: + ll = nfs3_readdir_loglevel (stat); + break; + + case NFS3_FSSTAT: + ll = nfs3_fsstat_loglevel (stat); + break; + + case NFS3_FSINFO: + ll = nfs3_fsstat_loglevel (stat); + break; + + case NFS3_PATHCONF: + ll = nfs3_fsstat_loglevel (stat); + break; + + case NFS3_COMMIT: + ll = nfs3_write_loglevel (stat); + break; + + default: + ll = GF_LOG_DEBUG; + break; + } + + return ll; +} void -nfs3_log_common_res (uint32_t xid, char *op, nfsstat3 stat, int pstat) +nfs3_log_common_res (uint32_t xid, int op, nfsstat3 stat, int pstat) { char errstr[1024]; + int ll = nfs3_loglevel (op, stat); - nfs3_stat_to_errstr (xid, op, stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s", errstr); + if (gf_log_loglevel < ll) + return; + nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr); + gf_log (GF_NFS3, ll, "%s", errstr); } void nfs3_log_readlink_res (uint32_t xid, nfsstat3 stat, int pstat, char *linkpath) { char errstr[1024]; + int ll = nfs3_loglevel (NFS3_READLINK, stat); + + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "READLINK", stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, target: %s", errstr, linkpath); + gf_log (GF_NFS3, ll, "%s, target: %s", + errstr, linkpath); } @@ -2319,14 +3423,18 @@ nfs3_log_read_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count, int is_eof, struct iovec *vec, int32_t veccount) { char errstr[1024]; + int ll = GF_LOG_DEBUG; + ll = nfs3_loglevel (NFS3_READ, stat); + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "READ", stat, pstat, errstr); if (vec) - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, count: %"PRIu32", is_eof:" + gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", is_eof:" " %d, vector: count: %d, len: %zd", errstr, count, is_eof, veccount, vec->iov_len); else - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, count: %"PRIu32", is_eof:" + gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", is_eof:" " %d", errstr, count, is_eof); } @@ -2336,25 +3444,32 @@ nfs3_log_write_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count, int stable, uint64_t wverf) { char errstr[1024]; + int ll = nfs3_loglevel (NFS3_WRITE, stat); + + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "WRITE", stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, count: %"PRIu32", %s,wverf: %"PRIu64 + gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", %s,wverf: %"PRIu64 , errstr, count, (stable == UNSTABLE)?"UNSTABLE":"STABLE", wverf); } void -nfs3_log_newfh_res (uint32_t xid, char *op, nfsstat3 stat, int pstat, +nfs3_log_newfh_res (uint32_t xid, int op, nfsstat3 stat, int pstat, struct nfs3_fh *newfh) { char errstr[1024]; char fhstr[1024]; + int ll = nfs3_loglevel (op, stat); - nfs3_stat_to_errstr (xid, op, stat, pstat, errstr); + if (gf_log_loglevel < ll) + return; + nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr); nfs3_fh_to_str (newfh, fhstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, %s", errstr, fhstr); + gf_log (GF_NFS3, nfs3_loglevel (op, stat), "%s, %s", errstr, fhstr); } @@ -2363,9 +3478,12 @@ nfs3_log_readdir_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf, count3 count, int is_eof) { char errstr[1024]; + int ll = nfs3_loglevel (NFS3_READDIR, stat); + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "READDIR", stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, count: %"PRIu32", cverf: %"PRIu64 + gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", cverf: %"PRIu64 ", is_eof: %d", errstr, count, cverf, is_eof); } @@ -2375,9 +3493,12 @@ nfs3_log_readdirp_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf, count3 dircount, count3 maxcount, int is_eof) { char errstr[1024]; + int ll = nfs3_loglevel (NFS3_READDIRP, stat); + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "READDIRPLUS", stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, dircount: %"PRIu32", maxcount: %" + gf_log (GF_NFS3, ll, "%s, dircount: %"PRIu32", maxcount: %" PRIu32", cverf: %"PRIu64", is_eof: %d", errstr, dircount, maxcount, cverf, is_eof); } @@ -2387,9 +3508,12 @@ void nfs3_log_commit_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t wverf) { char errstr[1024]; + int ll = nfs3_loglevel (NFS3_COMMIT, stat); + if (gf_log_loglevel < ll) + return; nfs3_stat_to_errstr (xid, "COMMIT", stat, pstat, errstr); - gf_log (GF_NFS3, GF_LOG_DEBUG, "%s, wverf: %"PRIu64, errstr, wverf); + gf_log (GF_NFS3, ll, "%s, wverf: %"PRIu64, errstr, wverf); } @@ -2399,6 +3523,9 @@ nfs3_log_readdir_call (uint32_t xid, struct nfs3_fh *fh, count3 dircount, { char fhstr[1024]; + if (gf_log_loglevel < GF_LOG_DEBUG) + return; + nfs3_fh_to_str (fh, fhstr); if (maxcount == 0) @@ -2420,7 +3547,7 @@ nfs3_fh_resolve_inode_done (nfs3_call_state_t *cs, inode_t *inode) return ret; gf_log (GF_NFS3, GF_LOG_TRACE, "FH inode resolved"); - ret = nfs_inode_loc_fill (inode, &cs->resolvedloc); + ret = nfs_inode_loc_fill (inode, &cs->resolvedloc, NFS_RESOLVE_EXIST); if (ret < 0) { gf_log (GF_NFS3, GF_LOG_ERROR, "inode loc fill failed"); goto err; @@ -2505,6 +3632,8 @@ nfs3_fh_resolve_entry_lookup_cbk (call_frame_t *frame, void *cookie, gf_log (GF_NFS3, GF_LOG_TRACE, "Entry looked up: %s", cs->resolvedloc.path); + memcpy (&cs->stbuf, buf, sizeof (*buf)); + memcpy (&cs->postparent, postparent, sizeof (*postparent)); linked_inode = inode_link (inode, cs->resolvedloc.parent, cs->resolvedloc.name, buf); if (linked_inode) { @@ -2517,12 +3646,6 @@ err: } - -int32_t -nfs3_fh_resolve_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries); - int nfs3_fh_resolve_found_entry (nfs3_call_state_t *cs, gf_dirent_t *candidate) { @@ -2637,52 +3760,13 @@ nfs3_fh_resolve_found (nfs3_call_state_t *cs, gf_dirent_t *candidate) int32_t -nfs3_fh_resolve_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd) -{ - nfs3_call_state_t *cs = NULL; - int ret = -EFAULT; - nfs_user_t nfu = {0, }; - - cs = frame->local; - cs->resolve_ret = op_ret; - cs->resolve_errno = op_errno; - - if (op_ret == -1) { - gf_log (GF_NFS3, GF_LOG_ERROR, "Dir open failed: %s: %s", - cs->resolvedloc.path, strerror (op_errno)); - nfs3_call_resume (cs); - goto err; - } else - gf_log (GF_NFS3, GF_LOG_TRACE, "Reading directory: %s", - cs->resolvedloc.path); - - nfs_user_root_create (&nfu); - /* Keep this directory fd_t around till we have either: - * a. found the entry, - * b. exhausted all the entries, - * c. decide to step into a child directory. - * - * This decision is made in nfs3_fh_resolve_check_response. - */ - cs->resolve_dir_fd = fd; - gf_log (GF_NFS3, GF_LOG_TRACE, "resolve new fd refed: 0x%lx, ref: %d", - (long)cs->resolve_dir_fd, cs->resolve_dir_fd->refcount); - ret = nfs_readdirp (cs->nfsx, cs->vol, &nfu, fd, GF_NFS3_DTPREF, 0, - nfs3_fh_resolve_readdir_cbk, cs); - -err: - return ret; -} - -int32_t -nfs3_fh_resolve_dir_lookup_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret,int32_t op_errno, - inode_t *inode, struct iatt *buf, dict_t *xattr, - struct iatt *postparent) +nfs3_fh_resolve_inode_lookup_cbk (call_frame_t *frame, void *cookie, + xlator_t *this, int32_t op_ret, + int32_t op_errno, inode_t *inode, + struct iatt *buf, dict_t *xattr, + struct iatt *postparent) { nfs3_call_state_t *cs = NULL; - nfs_user_t nfu = {0, }; inode_t *linked_inode = NULL; cs = frame->local; @@ -2695,21 +3779,27 @@ nfs3_fh_resolve_dir_lookup_cbk (call_frame_t *frame, void *cookie, cs->resolvedloc.path, strerror (op_errno)); nfs3_call_resume (cs); goto err; - } else - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir will be opened: %s", - cs->resolvedloc.path); + } - nfs_user_root_create (&nfu); + memcpy (&cs->stbuf, buf, sizeof(*buf)); + memcpy (&cs->postparent, buf, sizeof(*postparent)); linked_inode = inode_link (inode, cs->resolvedloc.parent, cs->resolvedloc.name, buf); if (linked_inode) { inode_lookup (linked_inode); - inode_unref (linked_inode); + inode_unref (cs->resolvedloc.inode); + cs->resolvedloc.inode = linked_inode; } - nfs_opendir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_fh_resolve_opendir_cbk, cs); - + /* If it is an entry lookup and we landed in the callback for hard + * inode resolution, it means the parent inode was not available and + * had to be resolved first. Now that is done, lets head back into + * entry resolution. + */ + if (cs->resolventry) + nfs3_fh_resolve_entry_hard (cs); + else + nfs3_call_resume (cs); err: return 0; } @@ -2752,47 +3842,6 @@ out: } -int -nfs3_fh_resolve_dir_hard (nfs3_call_state_t *cs, uuid_t dirgfid, char *entry) -{ - int ret = -EFAULT; - nfs_user_t nfu = {0, }; - - if (!cs) - return ret; - - cs->hashidx++; - nfs_loc_wipe (&cs->resolvedloc); - if (!nfs3_fh_resolve_validate_dirdepth (cs)) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir depth validation failed"); - nfs3_call_resume_estale (cs); - ret = 0; - goto out; - } - - nfs_user_root_create (&nfu); - gf_log (GF_NFS3, GF_LOG_TRACE, "FH hard dir resolution: gfid: %s, " - "entry: %s, next hashcount: %d", uuid_utoa (dirgfid), entry, - cs->hashidx); - ret = nfs_entry_loc_fill (cs->vol->itable, dirgfid, entry, - &cs->resolvedloc, NFS_RESOLVE_CREATE); - - if (ret == 0) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir will be opened: %s", - cs->resolvedloc.path); - ret = nfs_opendir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_fh_resolve_opendir_cbk, cs); - } else if (ret == -ENOENT) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir needs lookup: %s", - cs->resolvedloc.path); - ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_fh_resolve_dir_lookup_cbk, cs); - } -out: - return ret; -} - - /* * Called in a recursive code path, so if another * directory was opened in an earlier call during fh resolution, we must unref @@ -2831,100 +3880,6 @@ nfs3_fh_resolve_determine_response (nfs3_call_state_t *cs) { } -int -nfs3_fh_resolve_check_response (nfs3_call_state_t *cs) -{ - int ret = -EFAULT; - nfs_user_t nfu = {0, }; - int response = GF_NFS3_FHRESOLVE_NOTFOUND; - - if (!cs) - return ret; - - response = nfs3_fh_resolve_determine_response (cs); - switch (response) { - - case GF_NFS3_FHRESOLVE_DIRFOUND: - nfs3_fh_resolve_close_cwd (cs); - nfs3_fh_resolve_dir_hard (cs, cs->resolvedloc.inode->gfid, - cs->hashmatch->d_name); - break; - - case GF_NFS3_FHRESOLVE_FOUND: - nfs3_fh_resolve_close_cwd (cs); - nfs3_fh_resolve_found (cs, cs->entrymatch); - break; - - case GF_NFS3_FHRESOLVE_NOTFOUND: - nfs_user_root_create (&nfu); - nfs_readdirp (cs->nfsx, cs->vol, &nfu, cs->resolve_dir_fd, - GF_NFS3_DTPREF, cs->lastentryoffset, - nfs3_fh_resolve_readdir_cbk, cs); - break; - } - - return 0; -} - -int -nfs3_fh_resolve_search_dir (nfs3_call_state_t *cs, gf_dirent_t *entries) -{ - gf_dirent_t *candidate = NULL; - int ret = GF_NFS3_FHRESOLVE_NOTFOUND; - - if ((!cs) || (!entries)) - return -EFAULT; - - if (list_empty (&entries->list)) - goto search_done; - - list_for_each_entry (candidate, &entries->list, list) { - cs->lastentryoffset = candidate->d_off; - gf_log (GF_NFS3, GF_LOG_TRACE, "Candidate: %s, gfid: %s", - candidate->d_name, - uuid_utoa (candidate->d_stat.ia_gfid)); - ret = nfs3_fh_resolve_check_entry (&cs->resolvefh, candidate, - cs->hashidx); - if (ret == GF_NFS3_FHRESOLVE_FOUND) - cs->entrymatch = gf_dirent_for_name (candidate->d_name); - else if (ret == GF_NFS3_FHRESOLVE_DIRFOUND) { - if (cs->hashmatch) - gf_dirent_free (cs->hashmatch); - cs->hashmatch = gf_dirent_for_name (candidate->d_name); - } - } - -search_done: - return ret; -} - - -int32_t -nfs3_fh_resolve_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries) -{ - nfs3_call_state_t *cs = NULL; - nfs_user_t nfu = {0, }; - - cs = frame->local; - if (op_ret <= 0) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Directory read done: %s: %s", - cs->resolvedloc.path, strerror (op_ret)); - nfs3_fh_resolve_check_response (cs); - goto err; - } - - nfs3_fh_resolve_search_dir (cs, entries); - nfs_user_root_create (&nfu); - nfs_readdirp (cs->nfsx, cs->vol, &nfu, cs->resolve_dir_fd, - GF_NFS3_DTPREF, cs->lastentryoffset, - nfs3_fh_resolve_readdir_cbk, cs); - -err: - return 0; -} - /* Needs no extra argument since it knows that the fh to be resolved is in * resolvefh and that it needs to start looking from the root. */ @@ -2937,33 +3892,21 @@ nfs3_fh_resolve_inode_hard (nfs3_call_state_t *cs) if (!cs) return ret; - cs->hashidx++; + gf_log (GF_NFS3, GF_LOG_TRACE, "FH hard resolution for: gfid 0x%s", + uuid_utoa (cs->resolvefh.gfid)); + cs->hardresolved = 1; nfs_loc_wipe (&cs->resolvedloc); - if (!nfs3_fh_resolve_validate_dirdepth (cs)) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir depth validation failed"); - nfs3_call_resume_estale (cs); - ret = 0; + ret = nfs_gfid_loc_fill (cs->vol->itable, cs->resolvefh.gfid, + &cs->resolvedloc, NFS_RESOLVE_CREATE); + if (ret < 0) { + gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to fill loc using gfid: " + "%s", strerror (-ret)); goto out; } nfs_user_root_create (&nfu); - gf_log (GF_NFS3, GF_LOG_TRACE, "FH hard resolution for: gfid 0x%s" - ", hashcount: %d, current hashidx %d", - uuid_utoa (cs->resolvefh.gfid), - cs->resolvefh.hashcount, cs->hashidx); - ret = nfs_root_loc_fill (cs->vol->itable, &cs->resolvedloc); - - if (ret == 0) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir will be opened: %s", - cs->resolvedloc.path); - ret = nfs_opendir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_fh_resolve_opendir_cbk, cs); - } else if (ret == -ENOENT) { - gf_log (GF_NFS3, GF_LOG_TRACE, "Dir needs lookup: %s", - cs->resolvedloc.path); - ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, - nfs3_fh_resolve_dir_lookup_cbk, cs); - } + ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, + nfs3_fh_resolve_inode_lookup_cbk, cs); out: return ret; @@ -2982,8 +3925,8 @@ nfs3_fh_resolve_entry_hard (nfs3_call_state_t *cs) nfs_loc_wipe (&cs->resolvedloc); nfs_user_root_create (&nfu); gf_log (GF_NFS3, GF_LOG_TRACE, "FH hard resolution: gfid: %s " - ", entry: %s, hashidx: %d", uuid_utoa (cs->resolvefh.gfid), - cs->resolventry, cs->hashidx); + ", entry: %s", uuid_utoa (cs->resolvefh.gfid), + cs->resolventry); ret = nfs_entry_loc_fill (cs->vol->itable, cs->resolvefh.gfid, cs->resolventry, &cs->resolvedloc, @@ -2992,13 +3935,22 @@ nfs3_fh_resolve_entry_hard (nfs3_call_state_t *cs) if (ret == -2) { gf_log (GF_NFS3, GF_LOG_TRACE, "Entry needs lookup: %s", cs->resolvedloc.path); - if (nfs3_lookup_op (cs)) { + /* If the NFS op is lookup, let the resume callback + * handle the sending of the lookup fop. Similarly, + * if the NFS op is create, let the create call + * go ahead in the resume callback so that an EEXIST gets + * handled at posix without an extra fop at this point. + */ + if (nfs3_lookup_op (cs) || + (nfs3_create_op (cs) && !nfs3_create_exclusive_op (cs))) { cs->lookuptype = GF_NFS3_FRESH; cs->resolve_ret = 0; nfs3_call_resume (cs); - } else + } else { + cs->hardresolved = 1; nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, nfs3_fh_resolve_entry_lookup_cbk, cs); + } ret = 0; } else if (ret == -1) { gf_log (GF_NFS3, GF_LOG_TRACE, "Entry needs parent lookup: %s", @@ -3022,6 +3974,7 @@ nfs3_fh_resolve_inode (nfs3_call_state_t *cs) return ret; gf_log (GF_NFS3, GF_LOG_TRACE, "FH needs inode resolution"); + uuid_copy (cs->resolvedloc.gfid, cs->resolvefh.gfid); inode = inode_find (cs->vol->itable, cs->resolvefh.gfid); if (!inode) ret = nfs3_fh_resolve_inode_hard (cs); @@ -3119,6 +4072,11 @@ nfs3_fh_resolve_root (nfs3_call_state_t *cs) nfs_user_root_create (&nfu); gf_log (GF_NFS3, GF_LOG_TRACE, "Root needs lookup"); ret = nfs_root_loc_fill (cs->vol->itable, &cs->resolvedloc); + if (ret < 0) { + gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to lookup root from itable: %s", + strerror (-ret)); + goto out; + } ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc, nfs3_fh_resolve_root_lookup_cbk, cs); |