"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/nfs/server/src/nfs3-helpers.c" (16 Sep 2020, 96421 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nfs3-helpers.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
    3   This file is part of GlusterFS.
    4 
    5   This file is licensed to you under your choice of the GNU Lesser
    6   General Public License, version 3 or any later version (LGPLv3 or
    7   later), or the GNU General Public License, version 2 (GPLv2), in all
    8   cases as published by the Free Software Foundation.
    9 */
   10 
   11 #include <inttypes.h>
   12 
   13 #include <glusterfs/xlator.h>
   14 #include "nfs3.h"
   15 #include "nfs3-fh.h"
   16 #include "msg-nfs3.h"
   17 #include <glusterfs/rbthash.h>
   18 #include "nfs-fops.h"
   19 #include "nfs-inodes.h"
   20 #include "nfs-generics.h"
   21 #include "nfs3-helpers.h"
   22 #include "nfs-mem-types.h"
   23 #include <glusterfs/iatt.h>
   24 #include <glusterfs/common-utils.h>
   25 #include "nfs-messages.h"
   26 #include "mount3.h"
   27 #include <string.h>
   28 
   29 extern int
   30 nfs3_set_root_looked_up(struct nfs3_state *nfs3, struct nfs3_fh *rootfh);
   31 
   32 extern int
   33 nfs3_is_root_looked_up(struct nfs3_state *nfs3, struct nfs3_fh *rootfh);
   34 
   35 #define nfs3_call_resume(cst)                                                  \
   36     do {                                                                       \
   37         if (((cst)) && (cst)->resume_fn)                                       \
   38             (cst)->resume_fn(cst);                                             \
   39     } while (0)
   40 
   41 #define nfs3_call_resume_estale(csta)                                          \
   42     do {                                                                       \
   43         (csta)->resolve_ret = -1;                                              \
   44         (csta)->resolve_errno = ESTALE;                                        \
   45         nfs3_call_resume(csta);                                                \
   46     } while (0)
   47 
   48 struct nfs3stat_strerror {
   49     nfsstat3 stat;
   50     char strerror[100];
   51 };
   52 
   53 struct nfs3stat_strerror nfs3stat_strerror_table[] = {
   54     {NFS3_OK, "Call completed successfully."},
   55     {NFS3ERR_PERM, "Not owner"},
   56     {NFS3ERR_NOENT, "No such file or directory"},
   57     {NFS3ERR_IO, "I/O error"},
   58     {NFS3ERR_NXIO, "I/O error"},
   59     {NFS3ERR_ACCES, "Permission denied"},
   60     {NFS3ERR_EXIST, "File exists"},
   61     {NFS3ERR_XDEV, "Attempt to do a cross-device hard link"},
   62     {NFS3ERR_NODEV, "No such device"},
   63     {NFS3ERR_NOTDIR, "Not a directory"},
   64     {NFS3ERR_ISDIR, "Is a directory"},
   65     {NFS3ERR_INVAL, "Invalid argument for operation"},
   66     {NFS3ERR_FBIG, "File too large"},
   67     {NFS3ERR_NOSPC, "No space left on device"},
   68     {NFS3ERR_ROFS, "Read-only file system"},
   69     {NFS3ERR_MLINK, "Too many hard links"},
   70     {NFS3ERR_NAMETOOLONG, "Filename in operation was too long"},
   71     {NFS3ERR_NOTEMPTY, "Directory not empty"},
   72     {NFS3ERR_DQUOT, "Resource (quota) hard limit exceeded"},
   73     {NFS3ERR_STALE, "Invalid file handle"},
   74     {NFS3ERR_REMOTE, "Too many levels of remote in path"},
   75     {NFS3ERR_BADHANDLE, "Illegal NFS file handle"},
   76     {NFS3ERR_NOT_SYNC, "Update synchronization mismatch detected"},
   77     {NFS3ERR_BAD_COOKIE, "READDIR or READDIRPLUS cookie is stale"},
   78     {NFS3ERR_NOTSUPP, "Operation is not supported"},
   79     {NFS3ERR_TOOSMALL, "Buffer or request is too small"},
   80     {NFS3ERR_SERVERFAULT, "Error occurred on the server or IO Error"},
   81     {NFS3ERR_BADTYPE, "Type not supported by the server"},
   82     {NFS3ERR_JUKEBOX, "Cannot complete server initiated request"},
   83     {NFS3ERR_END_OF_LIST, "IO Error"},
   84 
   85 };
   86 
   87 uint64_t
   88 nfs3_iatt_gfid_to_ino(struct iatt *buf)
   89 {
   90     uint64_t ino = 0;
   91 
   92     if (!buf)
   93         return 0;
   94 
   95     if (gf_nfs_enable_ino32()) {
   96         ino = (uint32_t)nfs_hash_gfid(buf->ia_gfid);
   97         goto hashout;
   98     }
   99 
  100     /* from posix its guaranteed to send unique ino */
  101     ino = buf->ia_ino;
  102 
  103 hashout:
  104     return ino;
  105 }
  106 
  107 void
  108 nfs3_map_deviceid_to_statdev(struct iatt *ia, uint64_t deviceid)
  109 {
  110     if (!ia)
  111         return;
  112 
  113     ia->ia_dev = deviceid;
  114 }
  115 
  116 struct nfs3_fh
  117 nfs3_extract_nfs3_fh(nfs_fh3 fh)
  118 {
  119     struct nfs3_fh gfh;
  120 
  121     memcpy(&gfh, fh.data.data_val, fh.data.data_len);
  122     return gfh;
  123 }
  124 
  125 struct nfs3_fh
  126 nfs3_extract_lookup_fh(lookup3args *args)
  127 {
  128     return nfs3_extract_nfs3_fh(args->what.dir);
  129 }
  130 
  131 char *
  132 nfs3_extract_lookup_name(lookup3args *args)
  133 {
  134     return args->what.name;
  135 }
  136 
  137 nfsstat3
  138 nfs3_errno_to_nfsstat3(int errnum)
  139 {
  140     nfsstat3 stat = NFS3_OK;
  141 
  142     switch (errnum) {
  143         case 0:
  144             stat = NFS3_OK;
  145             break;
  146 
  147         case EPERM:
  148             stat = NFS3ERR_PERM;
  149             break;
  150 
  151         case ENOENT:
  152             stat = NFS3ERR_NOENT;
  153             break;
  154 
  155         case EACCES:
  156             stat = NFS3ERR_ACCES;
  157             break;
  158 
  159         case EEXIST:
  160             stat = NFS3ERR_EXIST;
  161             break;
  162 
  163         case EXDEV:
  164             stat = NFS3ERR_XDEV;
  165             break;
  166 
  167         case ENODEV:
  168             stat = NFS3ERR_NODEV;
  169             break;
  170 
  171         case EIO:
  172             stat = NFS3ERR_IO;
  173             break;
  174 
  175         case ENXIO:
  176             stat = NFS3ERR_NXIO;
  177             break;
  178 
  179         case ENOTDIR:
  180             stat = NFS3ERR_NOTDIR;
  181             break;
  182 
  183         case EISDIR:
  184             stat = NFS3ERR_ISDIR;
  185             break;
  186 
  187         case EINVAL:
  188             stat = NFS3ERR_INVAL;
  189             break;
  190 
  191         case ENOSPC:
  192             stat = NFS3ERR_NOSPC;
  193             break;
  194 
  195         case EROFS:
  196             stat = NFS3ERR_ROFS;
  197             break;
  198 
  199         case EFBIG:
  200             stat = NFS3ERR_FBIG;
  201             break;
  202 
  203         case EMLINK:
  204             stat = NFS3ERR_MLINK;
  205             break;
  206 
  207         case ENAMETOOLONG:
  208             stat = NFS3ERR_NAMETOOLONG;
  209             break;
  210 
  211         case ENOTEMPTY:
  212             stat = NFS3ERR_NOTEMPTY;
  213             break;
  214 
  215         case EFAULT:
  216             stat = NFS3ERR_SERVERFAULT;
  217             break;
  218 
  219         case ENOTSUP:
  220         case ENOSYS:
  221             stat = NFS3ERR_NOTSUPP;
  222             break;
  223 
  224         case EBADF:
  225             stat = NFS3ERR_BADTYPE;
  226             break;
  227 
  228         case ESTALE:
  229             stat = NFS3ERR_STALE;
  230             break;
  231 
  232         case ENOTCONN:
  233             stat = NFS3ERR_IO;
  234             break;
  235 
  236         case EDQUOT:
  237             stat = NFS3ERR_DQUOT;
  238             break;
  239 
  240         default:
  241             stat = NFS3ERR_SERVERFAULT;
  242             break;
  243     }
  244 
  245     return stat;
  246 }
  247 
  248 /*
  249  * Special case: If op_ret is -1, it's very unusual op_errno being
  250  * 0 which means something came wrong from upper layer(s). If it
  251  * happens by any means, then set NFS3 status to NFS3ERR_SERVERFAULT.
  252  */
  253 nfsstat3
  254 nfs3_cbk_errno_status(int32_t op_ret, int32_t op_errno)
  255 {
  256     if ((op_ret == -1) && (op_errno == 0)) {
  257         return NFS3ERR_SERVERFAULT;
  258     }
  259 
  260     return nfs3_errno_to_nfsstat3(op_errno);
  261 }
  262 
  263 void
  264 nfs3_fill_lookup3res_error(lookup3res *res, nfsstat3 stat, struct iatt *dirstat)
  265 {
  266     memset(res, 0, sizeof(*res));
  267     res->status = stat;
  268     if (!dirstat) {
  269         res->lookup3res_u.resfail.dir_attributes.attributes_follow = FALSE;
  270     }
  271 }
  272 
  273 void
  274 nfs3_stat_to_fattr3(struct iatt *buf, fattr3 *fa)
  275 {
  276     if (buf == NULL || fa == NULL) {
  277         errno = EINVAL;
  278         return;
  279     }
  280 
  281     if (IA_ISDIR(buf->ia_type))
  282         fa->type = NF3DIR;
  283     else if (IA_ISREG(buf->ia_type))
  284         fa->type = NF3REG;
  285     else if (IA_ISCHR(buf->ia_type))
  286         fa->type = NF3CHR;
  287     else if (IA_ISBLK(buf->ia_type))
  288         fa->type = NF3BLK;
  289     else if (IA_ISFIFO(buf->ia_type))
  290         fa->type = NF3FIFO;
  291     else if (IA_ISLNK(buf->ia_type))
  292         fa->type = NF3LNK;
  293     else if (IA_ISSOCK(buf->ia_type))
  294         fa->type = NF3SOCK;
  295 
  296     if (IA_PROT_RUSR(buf->ia_prot))
  297         fa->mode |= NFS3MODE_ROWNER;
  298     if (IA_PROT_WUSR(buf->ia_prot))
  299         fa->mode |= NFS3MODE_WOWNER;
  300     if (IA_PROT_XUSR(buf->ia_prot))
  301         fa->mode |= NFS3MODE_XOWNER;
  302 
  303     if (IA_PROT_RGRP(buf->ia_prot))
  304         fa->mode |= NFS3MODE_RGROUP;
  305     if (IA_PROT_WGRP(buf->ia_prot))
  306         fa->mode |= NFS3MODE_WGROUP;
  307     if (IA_PROT_XGRP(buf->ia_prot))
  308         fa->mode |= NFS3MODE_XGROUP;
  309 
  310     if (IA_PROT_ROTH(buf->ia_prot))
  311         fa->mode |= NFS3MODE_ROTHER;
  312     if (IA_PROT_WOTH(buf->ia_prot))
  313         fa->mode |= NFS3MODE_WOTHER;
  314     if (IA_PROT_XOTH(buf->ia_prot))
  315         fa->mode |= NFS3MODE_XOTHER;
  316 
  317     if (IA_PROT_SUID(buf->ia_prot))
  318         fa->mode |= NFS3MODE_SETXUID;
  319     if (IA_PROT_SGID(buf->ia_prot))
  320         fa->mode |= NFS3MODE_SETXGID;
  321     if (IA_PROT_STCKY(buf->ia_prot))
  322         fa->mode |= NFS3MODE_SAVESWAPTXT;
  323 
  324     fa->nlink = buf->ia_nlink;
  325     fa->uid = buf->ia_uid;
  326     fa->gid = buf->ia_gid;
  327     fa->size = buf->ia_size;
  328     fa->used = (buf->ia_blocks * 512);
  329 
  330     if ((IA_ISCHR(buf->ia_type) || IA_ISBLK(buf->ia_type))) {
  331         fa->rdev.specdata1 = ia_major(buf->ia_rdev);
  332         fa->rdev.specdata2 = ia_minor(buf->ia_rdev);
  333     } else {
  334         fa->rdev.specdata1 = 0;
  335         fa->rdev.specdata2 = 0;
  336     }
  337 
  338     fa->fsid = buf->ia_dev;
  339     fa->fileid = nfs3_iatt_gfid_to_ino(buf);
  340 
  341     fa->atime.seconds = buf->ia_atime;
  342     fa->atime.nseconds = buf->ia_atime_nsec;
  343 
  344     fa->ctime.seconds = buf->ia_ctime;
  345     fa->ctime.nseconds = buf->ia_ctime_nsec;
  346 
  347     fa->mtime.seconds = buf->ia_mtime;
  348     fa->mtime.nseconds = buf->ia_mtime_nsec;
  349 }
  350 
  351 post_op_attr
  352 nfs3_stat_to_post_op_attr(struct iatt *buf)
  353 {
  354     post_op_attr attr = {
  355         0,
  356     };
  357     if (!buf)
  358         return attr;
  359 
  360     /* Some performance translators return zero-filled stats when they
  361      * do not have up-to-date attributes. Need to handle this by not
  362      * returning these zeroed out attrs.
  363      */
  364     attr.attributes_follow = FALSE;
  365     if (gf_is_zero_filled_stat(buf))
  366         goto out;
  367 
  368     nfs3_stat_to_fattr3(buf, &(attr.post_op_attr_u.attributes));
  369     attr.attributes_follow = TRUE;
  370 
  371 out:
  372     return attr;
  373 }
  374 
  375 pre_op_attr
  376 nfs3_stat_to_pre_op_attr(struct iatt *pre)
  377 {
  378     pre_op_attr poa = {
  379         0,
  380     };
  381 
  382     /* Some performance translators return zero-filled stats when they
  383      * do not have up-to-date attributes. Need to handle this by not
  384      * returning these zeroed out attrs.
  385      */
  386     poa.attributes_follow = FALSE;
  387     if (gf_is_zero_filled_stat(pre))
  388         goto out;
  389 
  390     poa.attributes_follow = TRUE;
  391     poa.pre_op_attr_u.attributes.size = pre->ia_size;
  392     poa.pre_op_attr_u.attributes.mtime.seconds = pre->ia_mtime;
  393     poa.pre_op_attr_u.attributes.mtime.nseconds = pre->ia_mtime_nsec;
  394     poa.pre_op_attr_u.attributes.ctime.seconds = pre->ia_ctime;
  395     poa.pre_op_attr_u.attributes.ctime.nseconds = pre->ia_ctime_nsec;
  396 
  397 out:
  398     return poa;
  399 }
  400 
  401 void
  402 nfs3_fill_lookup3res_success(lookup3res *res, nfsstat3 stat, struct nfs3_fh *fh,
  403                              struct iatt *buf, struct iatt *postparent)
  404 {
  405     post_op_attr obj, dir;
  406     uint32_t fhlen = 0;
  407 
  408     res->status = stat;
  409     if (fh) {
  410         res->lookup3res_u.resok.object.data.data_val = (void *)fh;
  411         fhlen = nfs3_fh_compute_size();
  412         res->lookup3res_u.resok.object.data.data_len = fhlen;
  413     }
  414 
  415     obj.attributes_follow = FALSE;
  416     dir.attributes_follow = FALSE;
  417     obj = nfs3_stat_to_post_op_attr(buf);
  418     dir = nfs3_stat_to_post_op_attr(postparent);
  419 
  420     res->lookup3res_u.resok.obj_attributes = obj;
  421     res->lookup3res_u.resok.dir_attributes = dir;
  422 }
  423 
  424 void
  425 nfs3_fill_lookup3res(lookup3res *res, nfsstat3 stat, struct nfs3_fh *newfh,
  426                      struct iatt *buf, struct iatt *postparent,
  427                      uint64_t deviceid)
  428 {
  429     memset(res, 0, sizeof(*res));
  430     nfs3_map_deviceid_to_statdev(buf, deviceid);
  431     nfs3_map_deviceid_to_statdev(postparent, deviceid);
  432     if (stat != NFS3_OK)
  433         nfs3_fill_lookup3res_error(res, stat, postparent);
  434     else
  435         nfs3_fill_lookup3res_success(res, stat, newfh, buf, postparent);
  436 }
  437 
  438 struct nfs3_fh
  439 nfs3_extract_getattr_fh(getattr3args *args)
  440 {
  441     return nfs3_extract_nfs3_fh(args->object);
  442 }
  443 
  444 void
  445 nfs3_fill_getattr3res(getattr3res *res, nfsstat3 stat, struct iatt *buf,
  446                       uint64_t deviceid)
  447 {
  448     memset(res, 0, sizeof(*res));
  449     res->status = stat;
  450     if (stat != NFS3_OK)
  451         return;
  452 
  453     nfs3_map_deviceid_to_statdev(buf, deviceid);
  454     nfs3_stat_to_fattr3(buf, &(res->getattr3res_u.resok.obj_attributes));
  455 }
  456 
  457 struct nfs3_fh
  458 nfs3_extract_fsinfo_fh(fsinfo3args *args)
  459 {
  460     return nfs3_extract_nfs3_fh(args->fsroot);
  461 }
  462 
  463 void
  464 nfs3_fill_fsinfo3res(struct nfs3_state *nfs3, fsinfo3res *res, nfsstat3 status,
  465                      struct iatt *fsroot, uint64_t deviceid)
  466 {
  467     fsinfo3resok resok = {
  468         {0},
  469     };
  470     nfstime3 tdelta = GF_NFS3_TIMEDELTA_SECS;
  471 
  472     memset(res, 0, sizeof(*res));
  473     res->status = status;
  474     if (status != NFS3_OK)
  475         return;
  476 
  477     nfs3_map_deviceid_to_statdev(fsroot, deviceid);
  478     resok.obj_attributes = nfs3_stat_to_post_op_attr(fsroot);
  479     resok.rtmax = nfs3->readsize;
  480     resok.rtpref = nfs3->readsize;
  481     resok.rtmult = GF_NFS3_RTMULT;
  482     resok.wtmax = nfs3->writesize;
  483     resok.wtpref = nfs3->writesize;
  484     resok.wtmult = GF_NFS3_WTMULT;
  485     resok.dtpref = nfs3->readdirsize;
  486     resok.maxfilesize = GF_NFS3_MAXFILESIZE;
  487     resok.time_delta = tdelta;
  488     resok.properties = GF_NFS3_FS_PROP;
  489 
  490     res->fsinfo3res_u.resok = resok;
  491 }
  492 
  493 void
  494 nfs3_prep_lookup3args(lookup3args *args, struct nfs3_fh *fh, char *name)
  495 {
  496     memset(args, 0, sizeof(*args));
  497     args->what.dir.data.data_val = (void *)fh;
  498     args->what.name = name;
  499 }
  500 
  501 void
  502 nfs3_prep_getattr3args(getattr3args *args, struct nfs3_fh *fh)
  503 {
  504     memset(args, 0, sizeof(*args));
  505     args->object.data.data_val = (void *)fh;
  506 }
  507 
  508 void
  509 nfs3_prep_fsinfo3args(fsinfo3args *args, struct nfs3_fh *root)
  510 {
  511     memset(args, 0, sizeof(*args));
  512     args->fsroot.data.data_val = (void *)root;
  513 }
  514 
  515 char *
  516 nfsstat3_strerror(int stat)
  517 {
  518     int i;
  519     for (i = 0; nfs3stat_strerror_table[i].stat != NFS3ERR_END_OF_LIST; i++) {
  520         if (nfs3stat_strerror_table[i].stat == stat)
  521             return nfs3stat_strerror_table[i].strerror;
  522     }
  523 
  524     return nfs3stat_strerror_table[i].strerror;
  525 }
  526 
  527 void
  528 nfs3_prep_access3args(access3args *args, struct nfs3_fh *fh)
  529 {
  530     memset(args, 0, sizeof(*args));
  531     args->object.data.data_val = (void *)fh;
  532 }
  533 
  534 #define POSIX_READ 4
  535 #define POSIX_WRITE 2
  536 #define POSIX_EXEC 1
  537 
  538 uint32_t
  539 nfs3_accessbits(int32_t accbits)
  540 {
  541     uint32_t accresult = 0;
  542 
  543     if (accbits & POSIX_READ)
  544         accresult |= ACCESS3_READ;
  545 
  546     if (accbits & POSIX_WRITE)
  547         accresult |= (ACCESS3_MODIFY | ACCESS3_EXTEND | ACCESS3_DELETE);
  548 
  549     /* lookup on directory allowed only in case of execute permission */
  550     if (accbits & POSIX_EXEC)
  551         accresult |= (ACCESS3_EXECUTE | ACCESS3_LOOKUP);
  552 
  553     return accresult;
  554 }
  555 
  556 uint32_t
  557 nfs3_request_to_accessbits(int32_t accbits)
  558 {
  559     uint32_t acc_request = 0;
  560 
  561     if (accbits & ACCESS3_READ)
  562         acc_request |= POSIX_READ;
  563 
  564     if (accbits & (ACCESS3_MODIFY | ACCESS3_EXTEND | ACCESS3_DELETE))
  565         acc_request |= POSIX_WRITE;
  566 
  567     /* For lookup on directory check for execute permission */
  568     if (accbits & (ACCESS3_EXECUTE | ACCESS3_LOOKUP))
  569         acc_request |= POSIX_EXEC;
  570 
  571     return acc_request;
  572 }
  573 void
  574 nfs3_fill_access3res(access3res *res, nfsstat3 status, int32_t accbits,
  575                      int32_t reqaccbits)
  576 {
  577     uint32_t accres = 0;
  578 
  579     memset(res, 0, sizeof(*res));
  580     res->status = status;
  581     if (status != NFS3_OK)
  582         return;
  583 
  584     accres = nfs3_accessbits(accbits);
  585 
  586     /* do not answer what was not asked */
  587     res->access3res_u.resok.access = accres & reqaccbits;
  588 }
  589 
  590 void
  591 nfs3_prep_readdir3args(readdir3args *ra, struct nfs3_fh *fh)
  592 {
  593     memset(ra, 0, sizeof(*ra));
  594     ra->dir.data.data_val = (void *)fh;
  595 }
  596 
  597 int
  598 nfs3_is_dot_entry(char *entry)
  599 {
  600     int ret = 0;
  601 
  602     if (!entry)
  603         return 0;
  604 
  605     if (strcmp(entry, ".") == 0)
  606         ret = 1;
  607 
  608     return ret;
  609 }
  610 
  611 int
  612 nfs3_is_parentdir_entry(char *entry)
  613 {
  614     int ret = 0;
  615 
  616     if (!entry)
  617         return 0;
  618 
  619     if (strcmp(entry, "..") == 0)
  620         ret = 1;
  621 
  622     return ret;
  623 }
  624 
  625 void
  626 nfs3_funge_root_dotdot_dirent(gf_dirent_t *ent, struct nfs3_fh *dfh)
  627 {
  628     if ((!ent) || (!dfh))
  629         return;
  630 
  631     if (nfs3_fh_is_root_fh(dfh) && nfs3_is_parentdir_entry(ent->d_name)) {
  632         ent->d_ino = 1;
  633         ent->d_stat.ia_ino = 1;
  634     }
  635 
  636     if (nfs3_fh_is_root_fh(dfh) && nfs3_is_dot_entry(ent->d_name)) {
  637         ent->d_ino = 1;
  638         ent->d_stat.ia_ino = 1;
  639     }
  640 }
  641 
  642 entry3 *
  643 nfs3_fill_entry3(gf_dirent_t *entry, struct nfs3_fh *dfh)
  644 {
  645     entry3 *ent = NULL;
  646     int name_len = 0;
  647     if ((!entry) || (!dfh))
  648         return NULL;
  649 
  650     ent = GF_CALLOC(1, sizeof(*ent), gf_nfs_mt_entry3);
  651     if (!ent)
  652         return NULL;
  653 
  654     gf_msg_trace(GF_NFS3, 0, "Entry: %s", entry->d_name);
  655 
  656     /* If the entry is . or .., we need to replace the physical ino and gen
  657      * with 1 and 0 respectively if the directory is root. This funging is
  658      * needed because there is no parent directory of the root. In that
  659      * sense the behavior we provide is similar to the output of the
  660      * command: "stat /.."
  661      */
  662     entry->d_ino = nfs3_iatt_gfid_to_ino(&entry->d_stat);
  663     nfs3_funge_root_dotdot_dirent(entry, dfh);
  664     ent->fileid = entry->d_ino;
  665     ent->cookie = entry->d_off;
  666     name_len = strlen(entry->d_name);
  667     ent->name = GF_MALLOC(name_len + 1, gf_nfs_mt_char);
  668     if (!ent->name) {
  669         GF_FREE(ent);
  670         ent = NULL;
  671         goto err;
  672     }
  673     strcpy(ent->name, entry->d_name);
  674     ent->name[name_len] = '\0';
  675 
  676 err:
  677     return ent;
  678 }
  679 
  680 void
  681 nfs3_fill_post_op_fh3(struct nfs3_fh *fh, post_op_fh3 *pfh)
  682 {
  683     uint32_t fhlen = 0;
  684 
  685     if ((!fh) || (!pfh))
  686         return;
  687 
  688     pfh->handle_follows = 1;
  689     fhlen = nfs3_fh_compute_size();
  690     pfh->post_op_fh3_u.handle.data.data_val = (void *)fh;
  691     pfh->post_op_fh3_u.handle.data.data_len = fhlen;
  692 }
  693 
  694 post_op_fh3
  695 nfs3_fh_to_post_op_fh3(struct nfs3_fh *fh)
  696 {
  697     post_op_fh3 pfh = {
  698         0,
  699     };
  700     char *fhp = NULL;
  701 
  702     if (!fh)
  703         return pfh;
  704 
  705     pfh.handle_follows = 1;
  706 
  707     fhp = GF_MALLOC(sizeof(*fh), gf_nfs_mt_char);
  708     if (!fhp)
  709         return pfh;
  710 
  711     memcpy(fhp, fh, sizeof(*fh));
  712     nfs3_fill_post_op_fh3((struct nfs3_fh *)fhp, &pfh);
  713     return pfh;
  714 }
  715 
  716 entryp3 *
  717 nfs3_fill_entryp3(gf_dirent_t *entry, struct nfs3_fh *dirfh, uint64_t devid)
  718 {
  719     entryp3 *ent = NULL;
  720     struct nfs3_fh newfh = {
  721         {0},
  722     };
  723     int name_len = 0;
  724 
  725     if ((!entry) || (!dirfh))
  726         return NULL;
  727 
  728     /* If the entry is . or .., we need to replace the physical ino and gen
  729      * with 1 and 0 respectively if the directory is root. This funging is
  730      * needed because there is no parent directory of the root. In that
  731      * sense the behavior we provide is similar to the output of the
  732      * command: "stat /.."
  733      */
  734     entry->d_ino = nfs3_iatt_gfid_to_ino(&entry->d_stat);
  735     nfs3_funge_root_dotdot_dirent(entry, dirfh);
  736     gf_msg_trace(GF_NFS3, 0, "Entry: %s, ino: %" PRIu64, entry->d_name,
  737                  entry->d_ino);
  738     ent = GF_CALLOC(1, sizeof(*ent), gf_nfs_mt_entryp3);
  739     if (!ent)
  740         return NULL;
  741 
  742     ent->fileid = entry->d_ino;
  743     ent->cookie = entry->d_off;
  744     name_len = strlen(entry->d_name);
  745     ent->name = GF_MALLOC(name_len + 1, gf_nfs_mt_char);
  746     if (!ent->name) {
  747         GF_FREE(ent);
  748         ent = NULL;
  749         goto err;
  750     }
  751     strcpy(ent->name, entry->d_name);
  752     ent->name[name_len] = '\0';
  753 
  754     nfs3_fh_build_child_fh(dirfh, &entry->d_stat, &newfh);
  755     nfs3_map_deviceid_to_statdev(&entry->d_stat, devid);
  756     /* *
  757      * In tier volume, the readdirp send only to cold subvol
  758      * which will populate in the 'T' file entries in the result.
  759      * For such files an explicit stat call is required, by setting
  760      * following argument client will perform the same.
  761      *
  762      * The inode value for 'T' files and directory is NULL, so just
  763      * skip the check if it is directory.
  764      */
  765     if (!(IA_ISDIR(entry->d_stat.ia_type)) && (entry->inode == NULL))
  766         ent->name_attributes.attributes_follow = FALSE;
  767     else
  768         ent->name_attributes = nfs3_stat_to_post_op_attr(&entry->d_stat);
  769 
  770     ent->name_handle = nfs3_fh_to_post_op_fh3(&newfh);
  771 err:
  772     return ent;
  773 }
  774 
  775 void
  776 nfs3_fill_readdir3res(readdir3res *res, nfsstat3 stat, struct nfs3_fh *dirfh,
  777                       uint64_t cverf, struct iatt *dirstat,
  778                       gf_dirent_t *entries, count3 count, int is_eof,
  779                       uint64_t deviceid)
  780 {
  781     post_op_attr dirattr;
  782     entry3 *ent = NULL;
  783     entry3 *headentry = NULL;
  784     entry3 *preventry = NULL;
  785     count3 filled = 0;
  786     gf_dirent_t *listhead = NULL;
  787 
  788     memset(res, 0, sizeof(*res));
  789     res->status = stat;
  790     if (stat != NFS3_OK)
  791         return;
  792 
  793     nfs3_map_deviceid_to_statdev(dirstat, deviceid);
  794     dirattr = nfs3_stat_to_post_op_attr(dirstat);
  795     res->readdir3res_u.resok.dir_attributes = dirattr;
  796     res->readdir3res_u.resok.reply.eof = (bool_t)is_eof;
  797     memcpy(res->readdir3res_u.resok.cookieverf, &cverf, sizeof(cverf));
  798 
  799     filled = NFS3_READDIR_RESOK_SIZE;
  800     /* First entry is just the list head */
  801     listhead = entries;
  802     entries = entries->next;
  803     while (((entries) && (entries != listhead)) && (filled < count)) {
  804         /*
  805         if ((strcmp (entries->d_name, ".") == 0) ||
  806             (strcmp (entries->d_name, "..") == 0))
  807                 goto nextentry;
  808                 */
  809         ent = nfs3_fill_entry3(entries, dirfh);
  810         if (!ent)
  811             break;
  812 
  813         if (!headentry)
  814             headentry = ent;
  815 
  816         if (preventry) {
  817             preventry->nextentry = ent;
  818             preventry = ent;
  819         } else
  820             preventry = ent;
  821 
  822         filled += NFS3_ENTRY3_FIXED_SIZE + strlen(ent->name);
  823         // nextentry:
  824         entries = entries->next;
  825     }
  826 
  827     res->readdir3res_u.resok.reply.entries = headentry;
  828 
  829     return;
  830 }
  831 
  832 void
  833 nfs3_fill_readdirp3res(readdirp3res *res, nfsstat3 stat, struct nfs3_fh *dirfh,
  834                        uint64_t cverf, struct iatt *dirstat,
  835                        gf_dirent_t *entries, count3 dircount, count3 maxcount,
  836                        int is_eof, uint64_t deviceid)
  837 {
  838     post_op_attr dirattr;
  839     entryp3 *ent = NULL;
  840     entryp3 *headentry = NULL;
  841     entryp3 *preventry = NULL;
  842     count3 filled = 0;
  843     gf_dirent_t *listhead = NULL;
  844     int fhlen = 0;
  845 
  846     memset(res, 0, sizeof(*res));
  847     res->status = stat;
  848     if (stat != NFS3_OK)
  849         return;
  850 
  851     nfs3_map_deviceid_to_statdev(dirstat, deviceid);
  852     dirattr = nfs3_stat_to_post_op_attr(dirstat);
  853     res->readdirp3res_u.resok.dir_attributes = dirattr;
  854     res->readdirp3res_u.resok.reply.eof = (bool_t)is_eof;
  855     memcpy(res->readdirp3res_u.resok.cookieverf, &cverf, sizeof(cverf));
  856 
  857     filled = NFS3_READDIR_RESOK_SIZE;
  858     /* First entry is just the list head */
  859     listhead = entries;
  860     entries = entries->next;
  861     while (((entries) && (entries != listhead)) && (filled < maxcount)) {
  862         /* Linux does not display . and .. entries unless we provide
  863          * these entries here.
  864          */
  865         /*                if ((strcmp (entries->d_name, ".") == 0) ||
  866                             (strcmp (entries->d_name, "..") == 0))
  867                                 goto nextentry;
  868                                 */
  869         ent = nfs3_fill_entryp3(entries, dirfh, deviceid);
  870         if (!ent)
  871             break;
  872 
  873         if (!headentry)
  874             headentry = ent;
  875 
  876         if (preventry) {
  877             preventry->nextentry = ent;
  878             preventry = ent;
  879         } else
  880             preventry = ent;
  881 
  882         fhlen = ent->name_handle.post_op_fh3_u.handle.data.data_len;
  883         filled += NFS3_ENTRYP3_FIXED_SIZE + fhlen + strlen(ent->name);
  884         // nextentry:
  885         entries = entries->next;
  886     }
  887 
  888     res->readdirp3res_u.resok.reply.entries = headentry;
  889 
  890     return;
  891 }
  892 
  893 void
  894 nfs3_prep_readdirp3args(readdirp3args *ra, struct nfs3_fh *fh)
  895 {
  896     memset(ra, 0, sizeof(*ra));
  897     ra->dir.data.data_val = (void *)fh;
  898 }
  899 
  900 void
  901 nfs3_free_readdirp3res(readdirp3res *res)
  902 {
  903     entryp3 *ent = NULL;
  904     entryp3 *next = NULL;
  905 
  906     if (!res)
  907         return;
  908 
  909     ent = res->readdirp3res_u.resok.reply.entries;
  910     while (ent) {
  911         next = ent->nextentry;
  912         GF_FREE(ent->name);
  913         GF_FREE(ent->name_handle.post_op_fh3_u.handle.data.data_val);
  914         GF_FREE(ent);
  915         ent = next;
  916     }
  917 
  918     return;
  919 }
  920 
  921 void
  922 nfs3_free_readdir3res(readdir3res *res)
  923 {
  924     entry3 *ent = NULL;
  925     entry3 *next = NULL;
  926 
  927     if (!res)
  928         return;
  929 
  930     ent = res->readdir3res_u.resok.reply.entries;
  931     while (ent) {
  932         next = ent->nextentry;
  933         GF_FREE(ent->name);
  934         GF_FREE(ent);
  935         ent = next;
  936     }
  937 
  938     return;
  939 }
  940 
  941 void
  942 nfs3_prep_fsstat3args(fsstat3args *args, struct nfs3_fh *fh)
  943 {
  944     memset(args, 0, sizeof(*args));
  945     args->fsroot.data.data_val = (char *)fh;
  946 }
  947 
  948 void
  949 nfs3_fill_fsstat3res(fsstat3res *res, nfsstat3 stat, struct statvfs *fsbuf,
  950                      struct iatt *postbuf, uint64_t deviceid)
  951 {
  952     post_op_attr poa;
  953     fsstat3resok resok;
  954 
  955     memset(res, 0, sizeof(*res));
  956     res->status = stat;
  957     if (stat != NFS3_OK)
  958         return;
  959 
  960     nfs3_map_deviceid_to_statdev(postbuf, deviceid);
  961     poa = nfs3_stat_to_post_op_attr(postbuf);
  962     resok.tbytes = (size3)(fsbuf->f_frsize * fsbuf->f_blocks);
  963     resok.fbytes = (size3)(fsbuf->f_frsize * fsbuf->f_bfree);
  964     resok.abytes = (size3)(fsbuf->f_frsize * fsbuf->f_bavail);
  965     resok.tfiles = (size3)(fsbuf->f_files);
  966     resok.ffiles = (size3)(fsbuf->f_ffree);
  967     resok.afiles = (size3)(fsbuf->f_favail);
  968     resok.invarsec = 0;
  969 
  970     resok.obj_attributes = poa;
  971     res->fsstat3res_u.resok = resok;
  972 }
  973 
  974 int32_t
  975 nfs3_sattr3_to_setattr_valid(sattr3 *sattr, struct iatt *buf, mode_t *omode)
  976 {
  977     int32_t valid = 0;
  978     ia_prot_t prot = {
  979         0,
  980     };
  981     mode_t mode = 0;
  982 
  983     if (!sattr)
  984         return 0;
  985 
  986     if (sattr->mode.set_it) {
  987         valid |= GF_SET_ATTR_MODE;
  988 
  989         if (sattr->mode.set_mode3_u.mode & NFS3MODE_ROWNER) {
  990             mode |= S_IRUSR;
  991             prot.owner.read = 1;
  992         }
  993         if (sattr->mode.set_mode3_u.mode & NFS3MODE_WOWNER) {
  994             mode |= S_IWUSR;
  995             prot.owner.write = 1;
  996         }
  997         if (sattr->mode.set_mode3_u.mode & NFS3MODE_XOWNER) {
  998             mode |= S_IXUSR;
  999             prot.owner.exec = 1;
 1000         }
 1001 
 1002         if (sattr->mode.set_mode3_u.mode & NFS3MODE_RGROUP) {
 1003             mode |= S_IRGRP;
 1004             prot.group.read = 1;
 1005         }
 1006         if (sattr->mode.set_mode3_u.mode & NFS3MODE_WGROUP) {
 1007             mode |= S_IWGRP;
 1008             prot.group.write = 1;
 1009         }
 1010         if (sattr->mode.set_mode3_u.mode & NFS3MODE_XGROUP) {
 1011             mode |= S_IXGRP;
 1012             prot.group.exec = 1;
 1013         }
 1014 
 1015         if (sattr->mode.set_mode3_u.mode & NFS3MODE_ROTHER) {
 1016             mode |= S_IROTH;
 1017             prot.other.read = 1;
 1018         }
 1019         if (sattr->mode.set_mode3_u.mode & NFS3MODE_WOTHER) {
 1020             mode |= S_IWOTH;
 1021             prot.other.write = 1;
 1022         }
 1023         if (sattr->mode.set_mode3_u.mode & NFS3MODE_XOTHER) {
 1024             mode |= S_IXOTH;
 1025             prot.other.exec = 1;
 1026         }
 1027 
 1028         if (sattr->mode.set_mode3_u.mode & NFS3MODE_SETXUID) {
 1029             mode |= S_ISUID;
 1030             prot.suid = 1;
 1031         }
 1032         if (sattr->mode.set_mode3_u.mode & NFS3MODE_SETXGID) {
 1033             mode |= S_ISGID;
 1034             prot.sgid = 1;
 1035         }
 1036         if (sattr->mode.set_mode3_u.mode & NFS3MODE_SAVESWAPTXT) {
 1037             mode |= S_ISVTX;
 1038             prot.sticky = 1;
 1039         }
 1040 
 1041         if (buf)
 1042             buf->ia_prot = prot;
 1043         /* Create fop still requires the old mode_t style argument. */
 1044         if (omode)
 1045             *omode = mode;
 1046     }
 1047 
 1048     if (sattr->uid.set_it) {
 1049         valid |= GF_SET_ATTR_UID;
 1050         if (buf)
 1051             buf->ia_uid = sattr->uid.set_uid3_u.uid;
 1052     }
 1053 
 1054     if (sattr->gid.set_it) {
 1055         valid |= GF_SET_ATTR_GID;
 1056         if (buf)
 1057             buf->ia_gid = sattr->gid.set_gid3_u.gid;
 1058     }
 1059 
 1060     if (sattr->size.set_it) {
 1061         valid |= GF_SET_ATTR_SIZE;
 1062         if (buf)
 1063             buf->ia_size = sattr->size.set_size3_u.size;
 1064     }
 1065 
 1066     if (sattr->atime.set_it == SET_TO_CLIENT_TIME) {
 1067         valid |= GF_SET_ATTR_ATIME;
 1068         if (buf)
 1069             buf->ia_atime = sattr->atime.set_atime_u.atime.seconds;
 1070     }
 1071 
 1072     if (sattr->atime.set_it == SET_TO_SERVER_TIME) {
 1073         valid |= GF_SET_ATTR_ATIME;
 1074         if (buf)
 1075             buf->ia_atime = time(NULL);
 1076     }
 1077 
 1078     if (sattr->mtime.set_it == SET_TO_CLIENT_TIME) {
 1079         valid |= GF_SET_ATTR_MTIME;
 1080         if (buf)
 1081             buf->ia_mtime = sattr->mtime.set_mtime_u.mtime.seconds;
 1082     }
 1083 
 1084     if (sattr->mtime.set_it == SET_TO_SERVER_TIME) {
 1085         valid |= GF_SET_ATTR_MTIME;
 1086         if (buf)
 1087             buf->ia_mtime = time(NULL);
 1088     }
 1089 
 1090     return valid;
 1091 }
 1092 
 1093 wcc_data
 1094 nfs3_stat_to_wcc_data(struct iatt *pre, struct iatt *post)
 1095 {
 1096     wcc_data wd = {
 1097         {0},
 1098     };
 1099 
 1100     if (post)
 1101         wd.after = nfs3_stat_to_post_op_attr(post);
 1102     if (pre)
 1103         wd.before = nfs3_stat_to_pre_op_attr(pre);
 1104 
 1105     return wd;
 1106 }
 1107 
 1108 void
 1109 nfs3_fill_create3res(create3res *res, nfsstat3 stat, struct nfs3_fh *newfh,
 1110                      struct iatt *newbuf, struct iatt *preparent,
 1111                      struct iatt *postparent, uint64_t deviceid)
 1112 {
 1113     post_op_attr poa = {
 1114         0,
 1115     };
 1116     wcc_data dirwcc = {
 1117         {0},
 1118     };
 1119 
 1120     memset(res, 0, sizeof(*res));
 1121     res->status = stat;
 1122     if (stat != NFS3_OK)
 1123         return;
 1124 
 1125     nfs3_fill_post_op_fh3(newfh, &res->create3res_u.resok.obj);
 1126     nfs3_map_deviceid_to_statdev(newbuf, deviceid);
 1127     poa = nfs3_stat_to_post_op_attr(newbuf);
 1128     res->create3res_u.resok.obj_attributes = poa;
 1129     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1130     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1131     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1132 
 1133     res->create3res_u.resok.dir_wcc = dirwcc;
 1134 }
 1135 
 1136 void
 1137 nfs3_prep_create3args(create3args *args, struct nfs3_fh *fh, char *name)
 1138 {
 1139     memset(args, 0, sizeof(*args));
 1140     args->where.dir.data.data_val = (void *)fh;
 1141     args->where.name = name;
 1142 }
 1143 
 1144 void
 1145 nfs3_prep_setattr3args(setattr3args *args, struct nfs3_fh *fh)
 1146 {
 1147     memset(args, 0, sizeof(*args));
 1148     args->object.data.data_val = (void *)fh;
 1149 }
 1150 
 1151 void
 1152 nfs3_fill_setattr3res(setattr3res *res, nfsstat3 stat, struct iatt *preop,
 1153                       struct iatt *postop, uint64_t deviceid)
 1154 {
 1155     wcc_data wcc;
 1156     memset(res, 0, sizeof(*res));
 1157     res->status = stat;
 1158     if (stat != NFS3_OK)
 1159         return;
 1160 
 1161     nfs3_map_deviceid_to_statdev(preop, deviceid);
 1162     nfs3_map_deviceid_to_statdev(postop, deviceid);
 1163     wcc = nfs3_stat_to_wcc_data(preop, postop);
 1164     res->setattr3res_u.resok.obj_wcc = wcc;
 1165 }
 1166 
 1167 void
 1168 nfs3_prep_mkdir3args(mkdir3args *args, struct nfs3_fh *dirfh, char *name)
 1169 {
 1170     memset(args, 0, sizeof(*args));
 1171     args->where.dir.data.data_val = (void *)dirfh;
 1172     args->where.name = name;
 1173 }
 1174 
 1175 void
 1176 nfs3_fill_mkdir3res(mkdir3res *res, nfsstat3 stat, struct nfs3_fh *fh,
 1177                     struct iatt *buf, struct iatt *preparent,
 1178                     struct iatt *postparent, uint64_t deviceid)
 1179 {
 1180     wcc_data dirwcc;
 1181     post_op_attr poa;
 1182 
 1183     memset(res, 0, sizeof(*res));
 1184     res->status = stat;
 1185     if (stat != NFS3_OK)
 1186         return;
 1187 
 1188     nfs3_fill_post_op_fh3(fh, &res->mkdir3res_u.resok.obj);
 1189     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1190     poa = nfs3_stat_to_post_op_attr(buf);
 1191     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1192     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1193     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1194     res->mkdir3res_u.resok.obj_attributes = poa;
 1195     res->mkdir3res_u.resok.dir_wcc = dirwcc;
 1196 }
 1197 
 1198 void
 1199 nfs3_prep_symlink3args(symlink3args *args, struct nfs3_fh *dirfh, char *name,
 1200                        char *target)
 1201 {
 1202     memset(args, 0, sizeof(*args));
 1203     args->where.dir.data.data_val = (void *)dirfh;
 1204     args->where.name = name;
 1205     args->symlink.symlink_data = target;
 1206 }
 1207 
 1208 void
 1209 nfs3_fill_symlink3res(symlink3res *res, nfsstat3 stat, struct nfs3_fh *fh,
 1210                       struct iatt *buf, struct iatt *preparent,
 1211                       struct iatt *postparent, uint64_t deviceid)
 1212 {
 1213     wcc_data dirwcc;
 1214     post_op_attr poa;
 1215 
 1216     memset(res, 0, sizeof(*res));
 1217     res->status = stat;
 1218     if (stat != NFS3_OK)
 1219         return;
 1220 
 1221     nfs3_fill_post_op_fh3(fh, &res->symlink3res_u.resok.obj);
 1222     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1223     poa = nfs3_stat_to_post_op_attr(buf);
 1224     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1225     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1226     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1227     res->symlink3res_u.resok.obj_attributes = poa;
 1228     res->symlink3res_u.resok.dir_wcc = dirwcc;
 1229 }
 1230 
 1231 void
 1232 nfs3_prep_readlink3args(readlink3args *args, struct nfs3_fh *fh)
 1233 {
 1234     memset(args, 0, sizeof(*args));
 1235     args->symlink.data.data_val = (void *)fh;
 1236 }
 1237 
 1238 void
 1239 nfs3_fill_readlink3res(readlink3res *res, nfsstat3 stat, char *path,
 1240                        struct iatt *buf, uint64_t deviceid)
 1241 {
 1242     post_op_attr poa;
 1243 
 1244     memset(res, 0, sizeof(*res));
 1245     res->status = stat;
 1246 
 1247     if (stat != NFS3_OK)
 1248         return;
 1249 
 1250     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1251     poa = nfs3_stat_to_post_op_attr(buf);
 1252     res->readlink3res_u.resok.data = (void *)path;
 1253     res->readlink3res_u.resok.symlink_attributes = poa;
 1254 }
 1255 
 1256 void
 1257 nfs3_prep_mknod3args(mknod3args *args, struct nfs3_fh *fh, char *name)
 1258 {
 1259     memset(args, 0, sizeof(*args));
 1260     args->where.dir.data.data_val = (void *)fh;
 1261     args->where.name = name;
 1262 }
 1263 
 1264 void
 1265 nfs3_fill_mknod3res(mknod3res *res, nfsstat3 stat, struct nfs3_fh *fh,
 1266                     struct iatt *buf, struct iatt *preparent,
 1267                     struct iatt *postparent, uint64_t deviceid)
 1268 {
 1269     post_op_attr poa;
 1270     wcc_data wccdir;
 1271 
 1272     memset(res, 0, sizeof(*res));
 1273     res->status = stat;
 1274     if (stat != NFS3_OK)
 1275         return;
 1276 
 1277     nfs3_fill_post_op_fh3(fh, &res->mknod3res_u.resok.obj);
 1278     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1279     poa = nfs3_stat_to_post_op_attr(buf);
 1280     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1281     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1282     wccdir = nfs3_stat_to_wcc_data(preparent, postparent);
 1283     res->mknod3res_u.resok.obj_attributes = poa;
 1284     res->mknod3res_u.resok.dir_wcc = wccdir;
 1285 }
 1286 
 1287 void
 1288 nfs3_fill_remove3res(remove3res *res, nfsstat3 stat, struct iatt *preparent,
 1289                      struct iatt *postparent, uint64_t deviceid)
 1290 {
 1291     wcc_data dirwcc;
 1292 
 1293     memset(res, 0, sizeof(*res));
 1294     res->status = stat;
 1295     if (stat != NFS3_OK)
 1296         return;
 1297 
 1298     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1299     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1300     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1301     res->remove3res_u.resok.dir_wcc = dirwcc;
 1302 }
 1303 
 1304 void
 1305 nfs3_prep_remove3args(remove3args *args, struct nfs3_fh *fh, char *name)
 1306 {
 1307     memset(args, 0, sizeof(*args));
 1308     args->object.dir.data.data_val = (void *)fh;
 1309     args->object.name = name;
 1310 }
 1311 
 1312 void
 1313 nfs3_prep_rmdir3args(rmdir3args *args, struct nfs3_fh *fh, char *name)
 1314 {
 1315     memset(args, 0, sizeof(*args));
 1316     args->object.dir.data.data_val = (void *)fh;
 1317     args->object.name = name;
 1318 }
 1319 
 1320 void
 1321 nfs3_fill_rmdir3res(rmdir3res *res, nfsstat3 stat, struct iatt *preparent,
 1322                     struct iatt *postparent, uint64_t deviceid)
 1323 {
 1324     wcc_data dirwcc;
 1325     memset(res, 0, sizeof(*res));
 1326     res->status = stat;
 1327 
 1328     if (stat != NFS3_OK)
 1329         return;
 1330 
 1331     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1332     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1333     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1334     res->rmdir3res_u.resok.dir_wcc = dirwcc;
 1335 }
 1336 
 1337 void
 1338 nfs3_prep_link3args(link3args *args, struct nfs3_fh *target,
 1339                     struct nfs3_fh *dirfh, char *name)
 1340 {
 1341     memset(args, 0, sizeof(*args));
 1342     args->file.data.data_val = (void *)target;
 1343     args->link.dir.data.data_val = (void *)dirfh;
 1344     args->link.name = name;
 1345 }
 1346 
 1347 void
 1348 nfs3_fill_link3res(link3res *res, nfsstat3 stat, struct iatt *buf,
 1349                    struct iatt *preparent, struct iatt *postparent,
 1350                    uint64_t deviceid)
 1351 {
 1352     post_op_attr poa;
 1353     wcc_data dirwcc;
 1354 
 1355     memset(res, 0, sizeof(*res));
 1356     res->status = stat;
 1357     if (stat != NFS3_OK)
 1358         return;
 1359 
 1360     nfs3_map_deviceid_to_statdev(preparent, deviceid);
 1361     nfs3_map_deviceid_to_statdev(postparent, deviceid);
 1362     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1363     poa = nfs3_stat_to_post_op_attr(buf);
 1364     dirwcc = nfs3_stat_to_wcc_data(preparent, postparent);
 1365     res->link3res_u.resok.file_attributes = poa;
 1366     res->link3res_u.resok.linkdir_wcc = dirwcc;
 1367 }
 1368 
 1369 void
 1370 nfs3_prep_rename3args(rename3args *args, struct nfs3_fh *olddirfh,
 1371                       char *oldname, struct nfs3_fh *newdirfh, char *newname)
 1372 {
 1373     memset(args, 0, sizeof(*args));
 1374 
 1375     args->from.name = oldname;
 1376     args->from.dir.data.data_val = (void *)olddirfh;
 1377     args->to.name = newname;
 1378     args->to.dir.data.data_val = (void *)newdirfh;
 1379 }
 1380 
 1381 void
 1382 nfs3_fill_rename3res(rename3res *res, nfsstat3 stat, struct iatt *buf,
 1383                      struct iatt *preoldparent, struct iatt *postoldparent,
 1384                      struct iatt *prenewparent, struct iatt *postnewparent,
 1385                      uint64_t deviceid)
 1386 
 1387 {
 1388     wcc_data dirwcc;
 1389 
 1390     memset(res, 0, sizeof(*res));
 1391     res->status = stat;
 1392     if (stat != NFS3_OK)
 1393         return;
 1394 
 1395     nfs3_map_deviceid_to_statdev(preoldparent, deviceid);
 1396     nfs3_map_deviceid_to_statdev(postoldparent, deviceid);
 1397     nfs3_map_deviceid_to_statdev(prenewparent, deviceid);
 1398     nfs3_map_deviceid_to_statdev(postnewparent, deviceid);
 1399     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1400     dirwcc = nfs3_stat_to_wcc_data(preoldparent, postoldparent);
 1401     res->rename3res_u.resok.fromdir_wcc = dirwcc;
 1402     dirwcc = nfs3_stat_to_wcc_data(prenewparent, postnewparent);
 1403     res->rename3res_u.resok.todir_wcc = dirwcc;
 1404 }
 1405 
 1406 void
 1407 nfs3_prep_write3args(write3args *args, struct nfs3_fh *fh)
 1408 {
 1409     memset(args, 0, sizeof(*args));
 1410     args->file.data.data_val = (void *)fh;
 1411 }
 1412 
 1413 void
 1414 nfs3_fill_write3res(write3res *res, nfsstat3 stat, count3 count,
 1415                     stable_how stable, uint64_t wverf, struct iatt *prestat,
 1416                     struct iatt *poststat, uint64_t deviceid)
 1417 {
 1418     write3resok resok;
 1419     memset(res, 0, sizeof(*res));
 1420     res->status = stat;
 1421     if (stat != NFS3_OK)
 1422         return;
 1423 
 1424     nfs3_map_deviceid_to_statdev(prestat, deviceid);
 1425     nfs3_map_deviceid_to_statdev(poststat, deviceid);
 1426     resok.file_wcc = nfs3_stat_to_wcc_data(prestat, poststat);
 1427     resok.count = count;
 1428     resok.committed = stable;
 1429     memcpy(resok.verf, &wverf, sizeof(wverf));
 1430 
 1431     res->write3res_u.resok = resok;
 1432 }
 1433 
 1434 void
 1435 nfs3_prep_commit3args(commit3args *args, struct nfs3_fh *fh)
 1436 {
 1437     memset(args, 0, sizeof(*args));
 1438     args->file.data.data_val = (void *)fh;
 1439 }
 1440 
 1441 void
 1442 nfs3_fill_commit3res(commit3res *res, nfsstat3 stat, uint64_t wverf,
 1443                      struct iatt *prestat, struct iatt *poststat,
 1444                      uint64_t deviceid)
 1445 {
 1446     memset(res, 0, sizeof(*res));
 1447     res->status = stat;
 1448     if (stat != NFS3_OK)
 1449         return;
 1450 
 1451     nfs3_map_deviceid_to_statdev(poststat, deviceid);
 1452     nfs3_map_deviceid_to_statdev(prestat, deviceid);
 1453     res->commit3res_u.resok.file_wcc = nfs3_stat_to_wcc_data(prestat, poststat);
 1454     memcpy(res->commit3res_u.resok.verf, &wverf, sizeof(wverf));
 1455 }
 1456 
 1457 void
 1458 nfs3_fill_read3res(read3res *res, nfsstat3 stat, count3 count,
 1459                    struct iatt *poststat, int is_eof, uint64_t deviceid)
 1460 {
 1461     post_op_attr poa;
 1462 
 1463     memset(res, 0, sizeof(*res));
 1464     res->status = stat;
 1465     if (stat != NFS3_OK)
 1466         return;
 1467 
 1468     nfs3_map_deviceid_to_statdev(poststat, deviceid);
 1469     poa = nfs3_stat_to_post_op_attr(poststat);
 1470     res->read3res_u.resok.file_attributes = poa;
 1471     res->read3res_u.resok.count = count;
 1472     res->read3res_u.resok.eof = is_eof;
 1473     res->read3res_u.resok.data.data_len = count;
 1474 }
 1475 
 1476 void
 1477 nfs3_prep_read3args(read3args *args, struct nfs3_fh *fh)
 1478 {
 1479     memset(args, 0, sizeof(*args));
 1480     args->file.data.data_val = (void *)fh;
 1481 }
 1482 
 1483 void
 1484 nfs3_fill_pathconf3res(pathconf3res *res, nfsstat3 stat, struct iatt *buf,
 1485                        uint64_t deviceid)
 1486 {
 1487     pathconf3resok resok;
 1488 
 1489     memset(res, 0, sizeof(*res));
 1490     res->status = stat;
 1491     if (stat != NFS3_OK)
 1492         return;
 1493 
 1494     nfs3_map_deviceid_to_statdev(buf, deviceid);
 1495     resok.obj_attributes = nfs3_stat_to_post_op_attr(buf);
 1496     resok.linkmax = 256;
 1497     resok.name_max = NFS_NAME_MAX;
 1498     resok.no_trunc = TRUE;
 1499     resok.chown_restricted = FALSE;
 1500     resok.case_insensitive = FALSE;
 1501     resok.case_preserving = TRUE;
 1502 
 1503     res->pathconf3res_u.resok = resok;
 1504 }
 1505 
 1506 void
 1507 nfs3_prep_pathconf3args(pathconf3args *args, struct nfs3_fh *fh)
 1508 {
 1509     memset(args, 0, sizeof(*args));
 1510     args->object.data.data_val = (void *)fh;
 1511 }
 1512 
 1513 int
 1514 nfs3_verify_dircookie(struct nfs3_state *nfs3, fd_t *dirfd, cookie3 cookie,
 1515                       uint64_t cverf, nfsstat3 *stat)
 1516 {
 1517     int ret = -1;
 1518 
 1519     if ((!nfs3) || (!dirfd))
 1520         return -1;
 1521 
 1522     /* Can assume that this is first read on the dir, so cookie check
 1523      * is successful by default.
 1524      */
 1525     if (cookie == 0)
 1526         return 0;
 1527 
 1528     gf_msg_trace(GF_NFS3, 0,
 1529                  "Verifying cookie: cverf: %" PRIu64 ", cookie: %" PRIu64,
 1530                  cverf, cookie);
 1531     /* The cookie bad, no way cverf will be zero with a non-zero cookie. */
 1532     if ((cverf == 0) && (cookie != 0)) {
 1533         gf_msg_trace(GF_NFS3, 0, "Bad cookie requested");
 1534         if (stat)
 1535             *stat = NFS3ERR_BAD_COOKIE;
 1536         goto err;
 1537     }
 1538 
 1539     /* Yes, its true, our cookie is simply the fd_t address.
 1540      * NOTE: We used have the check for cookieverf but VMWare client sends
 1541      * a readdirp requests even after we've told it that EOF has been
 1542      * reached on the directory. This causes a problem because we close a
 1543      * dir fd_t after reaching EOF. The next readdirp sent by VMWare
 1544      * contains the address of the closed fd_t as cookieverf. Since we
 1545      * closed that fd_t, this readdirp results in a new opendir which will
 1546      * give an fd_t that will fail this check below.
 1547      */
 1548     /*        if ((cverf != (uint64_t)dirfd)) {
 1549                     gf_log (GF_NFS3, GF_LOG_TRACE, "Cookieverf does not match");
 1550                     if (stat)
 1551                             *stat = NFS3ERR_BAD_COOKIE;
 1552                     goto err;
 1553             }
 1554     */
 1555     gf_msg_trace(GF_NFS3, 0, "Cookie verified");
 1556     if (stat)
 1557         *stat = NFS3_OK;
 1558     ret = 0;
 1559 err:
 1560     return ret;
 1561 }
 1562 
 1563 void
 1564 nfs3_stat_to_errstr(uint32_t xid, char *op, nfsstat3 stat, int pstat,
 1565                     char *errstr, size_t len)
 1566 {
 1567     if ((!op) || (!errstr))
 1568         return;
 1569 
 1570     snprintf(errstr, len, "XID: %x, %s: NFS: %d(%s), POSIX: %d(%s)", xid, op,
 1571              stat, nfsstat3_strerror(stat), pstat, strerror(pstat));
 1572 }
 1573 
 1574 void
 1575 nfs3_log_common_call(uint32_t xid, char *op, struct nfs3_fh *fh)
 1576 {
 1577     char fhstr[1024];
 1578 
 1579     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1580         return;
 1581 
 1582     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1583     gf_msg_debug(GF_NFS3, 0, "XID: %x, %s: args: %s", xid, op, fhstr);
 1584 }
 1585 
 1586 void
 1587 nfs3_log_fh_entry_call(uint32_t xid, char *op, struct nfs3_fh *fh, char *name)
 1588 {
 1589     char fhstr[1024];
 1590 
 1591     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1592         return;
 1593     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1594     gf_msg_debug(GF_NFS3, 0, "XID: %x, %s: args: %s, name: %s", xid, op, fhstr,
 1595                  name);
 1596 }
 1597 
 1598 void
 1599 nfs3_log_rename_call(uint32_t xid, struct nfs3_fh *src, char *sname,
 1600                      struct nfs3_fh *dst, char *dname)
 1601 {
 1602     char sfhstr[1024];
 1603     char dfhstr[1024];
 1604 
 1605     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1606         return;
 1607     nfs3_fh_to_str(src, sfhstr, sizeof(sfhstr));
 1608     nfs3_fh_to_str(dst, dfhstr, sizeof(dfhstr));
 1609     gf_msg_debug(GF_NFS3, 0,
 1610                  "XID: %x, RENAME: args: Src: %s, "
 1611                  "name: %s, Dst: %s, name: %s",
 1612                  xid, sfhstr, sname, dfhstr, dname);
 1613 }
 1614 
 1615 void
 1616 nfs3_log_create_call(uint32_t xid, struct nfs3_fh *fh, char *name,
 1617                      createmode3 mode)
 1618 {
 1619     char fhstr[1024];
 1620     char *modestr = NULL;
 1621     char exclmode[] = "EXCLUSIVE";
 1622     char unchkd[] = "UNCHECKED";
 1623     char guarded[] = "GUARDED";
 1624 
 1625     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1626         return;
 1627     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1628     if (mode == EXCLUSIVE)
 1629         modestr = exclmode;
 1630     else if (mode == GUARDED)
 1631         modestr = guarded;
 1632     else
 1633         modestr = unchkd;
 1634 
 1635     gf_msg_debug(GF_NFS3, 0,
 1636                  "XID: %x, CREATE: args: %s, name: %s,"
 1637                  " mode: %s",
 1638                  xid, fhstr, name, modestr);
 1639 }
 1640 
 1641 void
 1642 nfs3_log_mknod_call(uint32_t xid, struct nfs3_fh *fh, char *name, int type)
 1643 {
 1644     char fhstr[1024];
 1645     char *modestr = NULL;
 1646     char chr[] = "CHAR";
 1647     char blk[] = "BLK";
 1648     char sock[] = "SOCK";
 1649     char fifo[] = "FIFO";
 1650 
 1651     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1652         return;
 1653     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1654     if (type == NF3CHR)
 1655         modestr = chr;
 1656     else if (type == NF3BLK)
 1657         modestr = blk;
 1658     else if (type == NF3SOCK)
 1659         modestr = sock;
 1660     else
 1661         modestr = fifo;
 1662 
 1663     gf_msg_debug(GF_NFS3, 0,
 1664                  "XID: %x, MKNOD: args: %s, name: %s,"
 1665                  " type: %s",
 1666                  xid, fhstr, name, modestr);
 1667 }
 1668 
 1669 void
 1670 nfs3_log_symlink_call(uint32_t xid, struct nfs3_fh *fh, char *name, char *tgt)
 1671 {
 1672     char fhstr[1024];
 1673 
 1674     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1675         return;
 1676     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1677     gf_msg_debug(GF_NFS3, 0,
 1678                  "XID: %x, SYMLINK: args: %s, name: %s,"
 1679                  " target: %s",
 1680                  xid, fhstr, name, tgt);
 1681 }
 1682 
 1683 void
 1684 nfs3_log_link_call(uint32_t xid, struct nfs3_fh *fh, char *name,
 1685                    struct nfs3_fh *tgt)
 1686 {
 1687     char dfhstr[1024];
 1688     char tfhstr[1024];
 1689 
 1690     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1691         return;
 1692     nfs3_fh_to_str(fh, dfhstr, sizeof(dfhstr));
 1693     nfs3_fh_to_str(tgt, tfhstr, sizeof(tfhstr));
 1694     gf_msg_debug(GF_NFS3, 0,
 1695                  "XID: %x, LINK: args: %s, name: %s,"
 1696                  " target: %s",
 1697                  xid, dfhstr, name, tfhstr);
 1698 }
 1699 
 1700 void
 1701 nfs3_log_rw_call(uint32_t xid, char *op, struct nfs3_fh *fh, offset3 offt,
 1702                  count3 count, int stablewrite)
 1703 {
 1704     char fhstr[1024];
 1705 
 1706     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 1707         return;
 1708     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 1709     if (stablewrite == -1)
 1710         gf_msg_debug(GF_NFS3, 0,
 1711                      "XID: %x, %s: args: %s, offset:"
 1712                      " %" PRIu64 ",  count: %" PRIu32,
 1713                      xid, op, fhstr, offt, count);
 1714     else
 1715         gf_msg_debug(GF_NFS3, 0,
 1716                      "XID: %x, %s: args: %s, offset:"
 1717                      " %" PRIu64 ",  count: %" PRIu32 ", %s",
 1718                      xid, op, fhstr, offt, count,
 1719                      (stablewrite == UNSTABLE) ? "UNSTABLE" : "STABLE");
 1720 }
 1721 
 1722 int
 1723 nfs3_getattr_loglevel(nfsstat3 stat)
 1724 {
 1725     int ll = GF_LOG_DEBUG;
 1726 
 1727     switch (stat) {
 1728         case NFS3ERR_PERM:
 1729             ll = GF_LOG_WARNING;
 1730             break;
 1731 
 1732         case NFS3ERR_NOENT:
 1733             ll = GF_LOG_WARNING;
 1734             break;
 1735 
 1736         case NFS3ERR_ACCES:
 1737             ll = GF_LOG_WARNING;
 1738             break;
 1739 
 1740         case NFS3ERR_EXIST:
 1741             ll = GF_LOG_WARNING;
 1742             break;
 1743 
 1744         case NFS3ERR_XDEV:
 1745             ll = GF_LOG_WARNING;
 1746             break;
 1747 
 1748         case NFS3ERR_NODEV:
 1749             ll = GF_LOG_WARNING;
 1750             break;
 1751 
 1752         case NFS3ERR_IO:
 1753             ll = GF_LOG_WARNING;
 1754             break;
 1755 
 1756         case NFS3ERR_NXIO:
 1757             ll = GF_LOG_WARNING;
 1758             break;
 1759 
 1760         case NFS3ERR_NOTDIR:
 1761             ll = GF_LOG_WARNING;
 1762             break;
 1763 
 1764         case NFS3ERR_ISDIR:
 1765             ll = GF_LOG_WARNING;
 1766             break;
 1767 
 1768         case NFS3ERR_INVAL:
 1769             ll = GF_LOG_WARNING;
 1770             break;
 1771 
 1772         case NFS3ERR_NOSPC:
 1773             ll = GF_LOG_WARNING;
 1774             break;
 1775 
 1776         case NFS3ERR_ROFS:
 1777             ll = GF_LOG_WARNING;
 1778             break;
 1779 
 1780         case NFS3ERR_FBIG:
 1781             ll = GF_LOG_WARNING;
 1782             break;
 1783 
 1784         case NFS3ERR_MLINK:
 1785             ll = GF_LOG_WARNING;
 1786             break;
 1787 
 1788         case NFS3ERR_NAMETOOLONG:
 1789             ll = GF_LOG_WARNING;
 1790             break;
 1791 
 1792         case NFS3ERR_NOTEMPTY:
 1793             ll = GF_LOG_WARNING;
 1794             break;
 1795 
 1796         case NFS3ERR_SERVERFAULT:
 1797             ll = GF_LOG_WARNING;
 1798             break;
 1799 
 1800         case NFS3ERR_NOTSUPP:
 1801             ll = GF_LOG_WARNING;
 1802             break;
 1803 
 1804         case NFS3ERR_BADHANDLE:
 1805             ll = GF_LOG_WARNING;
 1806             break;
 1807 
 1808         case NFS3ERR_STALE:
 1809             ll = GF_LOG_WARNING;
 1810             break;
 1811 
 1812         case NFS3ERR_DQUOT:
 1813             ll = GF_LOG_WARNING;
 1814             break;
 1815 
 1816         default:
 1817             ll = GF_LOG_DEBUG;
 1818             break;
 1819     }
 1820 
 1821     return ll;
 1822 }
 1823 
 1824 int
 1825 nfs3_setattr_loglevel(nfsstat3 stat)
 1826 {
 1827     int ll = GF_LOG_DEBUG;
 1828 
 1829     switch (stat) {
 1830         case NFS3ERR_NOENT:
 1831             ll = GF_LOG_WARNING;
 1832             break;
 1833 
 1834         case NFS3ERR_EXIST:
 1835             ll = GF_LOG_WARNING;
 1836             break;
 1837 
 1838         case NFS3ERR_XDEV:
 1839             ll = GF_LOG_WARNING;
 1840             break;
 1841 
 1842         case NFS3ERR_NODEV:
 1843             ll = GF_LOG_WARNING;
 1844             break;
 1845 
 1846         case NFS3ERR_IO:
 1847             ll = GF_LOG_WARNING;
 1848             break;
 1849 
 1850         case NFS3ERR_NXIO:
 1851             ll = GF_LOG_WARNING;
 1852             break;
 1853 
 1854         case NFS3ERR_NOTDIR:
 1855             ll = GF_LOG_WARNING;
 1856             break;
 1857 
 1858         case NFS3ERR_ISDIR:
 1859             ll = GF_LOG_WARNING;
 1860             break;
 1861 
 1862         case NFS3ERR_INVAL:
 1863             ll = GF_LOG_WARNING;
 1864             break;
 1865 
 1866         case NFS3ERR_NOSPC:
 1867             ll = GF_LOG_WARNING;
 1868             break;
 1869 
 1870         case NFS3ERR_ROFS:
 1871             ll = GF_LOG_WARNING;
 1872             break;
 1873 
 1874         case NFS3ERR_FBIG:
 1875             ll = GF_LOG_WARNING;
 1876             break;
 1877 
 1878         case NFS3ERR_MLINK:
 1879             ll = GF_LOG_WARNING;
 1880             break;
 1881 
 1882         case NFS3ERR_NAMETOOLONG:
 1883             ll = GF_LOG_WARNING;
 1884             break;
 1885 
 1886         case NFS3ERR_NOTEMPTY:
 1887             ll = GF_LOG_WARNING;
 1888             break;
 1889 
 1890         case NFS3ERR_SERVERFAULT:
 1891             ll = GF_LOG_WARNING;
 1892             break;
 1893 
 1894         case NFS3ERR_NOTSUPP:
 1895             ll = GF_LOG_WARNING;
 1896             break;
 1897 
 1898         case NFS3ERR_BADHANDLE:
 1899             ll = GF_LOG_WARNING;
 1900             break;
 1901 
 1902         case NFS3ERR_STALE:
 1903             ll = GF_LOG_WARNING;
 1904             break;
 1905 
 1906         case NFS3ERR_DQUOT:
 1907             ll = GF_LOG_WARNING;
 1908             break;
 1909 
 1910         default:
 1911             ll = GF_LOG_DEBUG;
 1912             break;
 1913     }
 1914 
 1915     return ll;
 1916 }
 1917 
 1918 int
 1919 nfs3_lookup_loglevel(nfsstat3 stat)
 1920 {
 1921     int ll = GF_LOG_DEBUG;
 1922 
 1923     switch (stat) {
 1924         case NFS3ERR_PERM:
 1925             ll = GF_LOG_WARNING;
 1926             break;
 1927 
 1928         case NFS3ERR_ACCES:
 1929             ll = GF_LOG_WARNING;
 1930             break;
 1931 
 1932         case NFS3ERR_EXIST:
 1933             ll = GF_LOG_WARNING;
 1934             break;
 1935 
 1936         case NFS3ERR_XDEV:
 1937             ll = GF_LOG_WARNING;
 1938             break;
 1939 
 1940         case NFS3ERR_NODEV:
 1941             ll = GF_LOG_WARNING;
 1942             break;
 1943 
 1944         case NFS3ERR_IO:
 1945             ll = GF_LOG_WARNING;
 1946             break;
 1947 
 1948         case NFS3ERR_NXIO:
 1949             ll = GF_LOG_WARNING;
 1950             break;
 1951 
 1952         case NFS3ERR_NOTDIR:
 1953             ll = GF_LOG_WARNING;
 1954             break;
 1955 
 1956         case NFS3ERR_ISDIR:
 1957             ll = GF_LOG_WARNING;
 1958             break;
 1959 
 1960         case NFS3ERR_INVAL:
 1961             ll = GF_LOG_WARNING;
 1962             break;
 1963 
 1964         case NFS3ERR_NOSPC:
 1965             ll = GF_LOG_WARNING;
 1966             break;
 1967 
 1968         case NFS3ERR_ROFS:
 1969             ll = GF_LOG_WARNING;
 1970             break;
 1971 
 1972         case NFS3ERR_FBIG:
 1973             ll = GF_LOG_WARNING;
 1974             break;
 1975 
 1976         case NFS3ERR_MLINK:
 1977             ll = GF_LOG_WARNING;
 1978             break;
 1979 
 1980         case NFS3ERR_NAMETOOLONG:
 1981             ll = GF_LOG_WARNING;
 1982             break;
 1983 
 1984         case NFS3ERR_NOTEMPTY:
 1985             ll = GF_LOG_WARNING;
 1986             break;
 1987 
 1988         case NFS3ERR_SERVERFAULT:
 1989             ll = GF_LOG_WARNING;
 1990             break;
 1991 
 1992         case NFS3ERR_NOTSUPP:
 1993             ll = GF_LOG_WARNING;
 1994             break;
 1995 
 1996         case NFS3ERR_BADHANDLE:
 1997             ll = GF_LOG_WARNING;
 1998             break;
 1999 
 2000         case NFS3ERR_STALE:
 2001             ll = GF_LOG_WARNING;
 2002             break;
 2003 
 2004         case NFS3ERR_DQUOT:
 2005             ll = GF_LOG_WARNING;
 2006             break;
 2007 
 2008         default:
 2009             ll = GF_LOG_DEBUG;
 2010             break;
 2011     }
 2012 
 2013     return ll;
 2014 }
 2015 
 2016 int
 2017 nfs3_access_loglevel(nfsstat3 stat)
 2018 {
 2019     int ll = GF_LOG_DEBUG;
 2020 
 2021     switch (stat) {
 2022         case NFS3ERR_NOENT:
 2023             ll = GF_LOG_WARNING;
 2024             break;
 2025 
 2026         case NFS3ERR_EXIST:
 2027             ll = GF_LOG_WARNING;
 2028             break;
 2029 
 2030         case NFS3ERR_XDEV:
 2031             ll = GF_LOG_WARNING;
 2032             break;
 2033 
 2034         case NFS3ERR_NODEV:
 2035             ll = GF_LOG_WARNING;
 2036             break;
 2037 
 2038         case NFS3ERR_IO:
 2039             ll = GF_LOG_WARNING;
 2040             break;
 2041 
 2042         case NFS3ERR_NXIO:
 2043             ll = GF_LOG_WARNING;
 2044             break;
 2045 
 2046         case NFS3ERR_NOTDIR:
 2047             ll = GF_LOG_WARNING;
 2048             break;
 2049 
 2050         case NFS3ERR_ISDIR:
 2051             ll = GF_LOG_WARNING;
 2052             break;
 2053 
 2054         case NFS3ERR_INVAL:
 2055             ll = GF_LOG_WARNING;
 2056             break;
 2057 
 2058         case NFS3ERR_NOSPC:
 2059             ll = GF_LOG_WARNING;
 2060             break;
 2061 
 2062         case NFS3ERR_ROFS:
 2063             ll = GF_LOG_WARNING;
 2064             break;
 2065 
 2066         case NFS3ERR_FBIG:
 2067             ll = GF_LOG_WARNING;
 2068             break;
 2069 
 2070         case NFS3ERR_MLINK:
 2071             ll = GF_LOG_WARNING;
 2072             break;
 2073 
 2074         case NFS3ERR_NAMETOOLONG:
 2075             ll = GF_LOG_WARNING;
 2076             break;
 2077 
 2078         case NFS3ERR_NOTEMPTY:
 2079             ll = GF_LOG_WARNING;
 2080             break;
 2081 
 2082         case NFS3ERR_SERVERFAULT:
 2083             ll = GF_LOG_WARNING;
 2084             break;
 2085 
 2086         case NFS3ERR_NOTSUPP:
 2087             ll = GF_LOG_WARNING;
 2088             break;
 2089 
 2090         case NFS3ERR_BADHANDLE:
 2091             ll = GF_LOG_WARNING;
 2092             break;
 2093 
 2094         case NFS3ERR_STALE:
 2095             ll = GF_LOG_WARNING;
 2096             break;
 2097 
 2098         case NFS3ERR_DQUOT:
 2099             ll = GF_LOG_WARNING;
 2100             break;
 2101 
 2102         default:
 2103             ll = GF_LOG_DEBUG;
 2104             break;
 2105     }
 2106 
 2107     return ll;
 2108 }
 2109 
 2110 int
 2111 nfs3_readlink_loglevel(nfsstat3 stat)
 2112 {
 2113     int ll = GF_LOG_DEBUG;
 2114 
 2115     switch (stat) {
 2116         case NFS3ERR_EXIST:
 2117             ll = GF_LOG_WARNING;
 2118             break;
 2119 
 2120         case NFS3ERR_XDEV:
 2121             ll = GF_LOG_WARNING;
 2122             break;
 2123 
 2124         case NFS3ERR_NODEV:
 2125             ll = GF_LOG_WARNING;
 2126             break;
 2127 
 2128         case NFS3ERR_IO:
 2129             ll = GF_LOG_WARNING;
 2130             break;
 2131 
 2132         case NFS3ERR_NXIO:
 2133             ll = GF_LOG_WARNING;
 2134             break;
 2135 
 2136         case NFS3ERR_NOTDIR:
 2137             ll = GF_LOG_WARNING;
 2138             break;
 2139 
 2140         case NFS3ERR_ISDIR:
 2141             ll = GF_LOG_WARNING;
 2142             break;
 2143 
 2144         case NFS3ERR_INVAL:
 2145             ll = GF_LOG_WARNING;
 2146             break;
 2147 
 2148         case NFS3ERR_NOSPC:
 2149             ll = GF_LOG_WARNING;
 2150             break;
 2151 
 2152         case NFS3ERR_ROFS:
 2153             ll = GF_LOG_WARNING;
 2154             break;
 2155 
 2156         case NFS3ERR_FBIG:
 2157             ll = GF_LOG_WARNING;
 2158             break;
 2159 
 2160         case NFS3ERR_MLINK:
 2161             ll = GF_LOG_WARNING;
 2162             break;
 2163 
 2164         case NFS3ERR_NOTEMPTY:
 2165             ll = GF_LOG_WARNING;
 2166             break;
 2167 
 2168         case NFS3ERR_SERVERFAULT:
 2169             ll = GF_LOG_WARNING;
 2170             break;
 2171 
 2172         case NFS3ERR_NOTSUPP:
 2173             ll = GF_LOG_WARNING;
 2174             break;
 2175 
 2176         case NFS3ERR_BADHANDLE:
 2177             ll = GF_LOG_WARNING;
 2178             break;
 2179 
 2180         case NFS3ERR_STALE:
 2181             ll = GF_LOG_WARNING;
 2182             break;
 2183 
 2184         case NFS3ERR_DQUOT:
 2185             ll = GF_LOG_WARNING;
 2186             break;
 2187 
 2188         default:
 2189             ll = GF_LOG_DEBUG;
 2190             break;
 2191     }
 2192 
 2193     return ll;
 2194 }
 2195 
 2196 int
 2197 nfs3_read_loglevel(nfsstat3 stat)
 2198 {
 2199     int ll = GF_LOG_DEBUG;
 2200 
 2201     switch (stat) {
 2202         case NFS3ERR_NOENT:
 2203             ll = GF_LOG_WARNING;
 2204             break;
 2205 
 2206         case NFS3ERR_EXIST:
 2207             ll = GF_LOG_WARNING;
 2208             break;
 2209 
 2210         case NFS3ERR_XDEV:
 2211             ll = GF_LOG_WARNING;
 2212             break;
 2213 
 2214         case NFS3ERR_NODEV:
 2215             ll = GF_LOG_WARNING;
 2216             break;
 2217 
 2218         case NFS3ERR_IO:
 2219             ll = GF_LOG_WARNING;
 2220             break;
 2221 
 2222         case NFS3ERR_NXIO:
 2223             ll = GF_LOG_WARNING;
 2224             break;
 2225 
 2226         case NFS3ERR_NOTDIR:
 2227             ll = GF_LOG_WARNING;
 2228             break;
 2229 
 2230         case NFS3ERR_ISDIR:
 2231             ll = GF_LOG_WARNING;
 2232             break;
 2233 
 2234         case NFS3ERR_INVAL:
 2235             ll = GF_LOG_WARNING;
 2236             break;
 2237 
 2238         case NFS3ERR_NOSPC:
 2239             ll = GF_LOG_WARNING;
 2240             break;
 2241 
 2242         case NFS3ERR_ROFS:
 2243             ll = GF_LOG_WARNING;
 2244             break;
 2245 
 2246         case NFS3ERR_FBIG:
 2247             ll = GF_LOG_WARNING;
 2248             break;
 2249 
 2250         case NFS3ERR_MLINK:
 2251             ll = GF_LOG_WARNING;
 2252             break;
 2253 
 2254         case NFS3ERR_NAMETOOLONG:
 2255             ll = GF_LOG_WARNING;
 2256             break;
 2257 
 2258         case NFS3ERR_NOTEMPTY:
 2259             ll = GF_LOG_WARNING;
 2260             break;
 2261 
 2262         case NFS3ERR_SERVERFAULT:
 2263             ll = GF_LOG_WARNING;
 2264             break;
 2265 
 2266         case NFS3ERR_NOTSUPP:
 2267             ll = GF_LOG_WARNING;
 2268             break;
 2269 
 2270         case NFS3ERR_BADHANDLE:
 2271             ll = GF_LOG_WARNING;
 2272             break;
 2273 
 2274         case NFS3ERR_STALE:
 2275             ll = GF_LOG_WARNING;
 2276             break;
 2277 
 2278         case NFS3ERR_DQUOT:
 2279             ll = GF_LOG_WARNING;
 2280             break;
 2281 
 2282         default:
 2283             ll = GF_LOG_DEBUG;
 2284             break;
 2285     }
 2286 
 2287     return ll;
 2288 }
 2289 
 2290 int
 2291 nfs3_write_loglevel(nfsstat3 stat)
 2292 {
 2293     int ll = GF_LOG_DEBUG;
 2294 
 2295     switch (stat) {
 2296         case NFS3ERR_NOENT:
 2297             ll = GF_LOG_WARNING;
 2298             break;
 2299 
 2300         case NFS3ERR_EXIST:
 2301             ll = GF_LOG_WARNING;
 2302             break;
 2303 
 2304         case NFS3ERR_XDEV:
 2305             ll = GF_LOG_WARNING;
 2306             break;
 2307 
 2308         case NFS3ERR_NODEV:
 2309             ll = GF_LOG_WARNING;
 2310             break;
 2311 
 2312         case NFS3ERR_IO:
 2313             ll = GF_LOG_WARNING;
 2314             break;
 2315 
 2316         case NFS3ERR_NXIO:
 2317             ll = GF_LOG_WARNING;
 2318             break;
 2319 
 2320         case NFS3ERR_NOTDIR:
 2321             ll = GF_LOG_WARNING;
 2322             break;
 2323 
 2324         case NFS3ERR_ISDIR:
 2325             ll = GF_LOG_WARNING;
 2326             break;
 2327 
 2328         case NFS3ERR_INVAL:
 2329             ll = GF_LOG_WARNING;
 2330             break;
 2331 
 2332         case NFS3ERR_NOSPC:
 2333             ll = GF_LOG_WARNING;
 2334             break;
 2335 
 2336         case NFS3ERR_ROFS:
 2337             ll = GF_LOG_WARNING;
 2338             break;
 2339 
 2340         case NFS3ERR_FBIG:
 2341             ll = GF_LOG_WARNING;
 2342             break;
 2343 
 2344         case NFS3ERR_MLINK:
 2345             ll = GF_LOG_WARNING;
 2346             break;
 2347 
 2348         case NFS3ERR_NAMETOOLONG:
 2349             ll = GF_LOG_WARNING;
 2350             break;
 2351 
 2352         case NFS3ERR_NOTEMPTY:
 2353             ll = GF_LOG_WARNING;
 2354             break;
 2355 
 2356         case NFS3ERR_SERVERFAULT:
 2357             ll = GF_LOG_WARNING;
 2358             break;
 2359 
 2360         case NFS3ERR_NOTSUPP:
 2361             ll = GF_LOG_WARNING;
 2362             break;
 2363 
 2364         case NFS3ERR_BADHANDLE:
 2365             ll = GF_LOG_WARNING;
 2366             break;
 2367 
 2368         case NFS3ERR_STALE:
 2369             ll = GF_LOG_WARNING;
 2370             break;
 2371 
 2372         case NFS3ERR_DQUOT:
 2373             ll = GF_LOG_WARNING;
 2374             break;
 2375 
 2376         default:
 2377             ll = GF_LOG_DEBUG;
 2378             break;
 2379     }
 2380 
 2381     return ll;
 2382 }
 2383 
 2384 int
 2385 nfs3_create_loglevel(nfsstat3 stat)
 2386 {
 2387     int ll = GF_LOG_DEBUG;
 2388 
 2389     switch (stat) {
 2390         case NFS3ERR_NOENT:
 2391             ll = GF_LOG_WARNING;
 2392             break;
 2393 
 2394         case NFS3ERR_EXIST:
 2395             ll = GF_LOG_WARNING;
 2396             break;
 2397 
 2398         case NFS3ERR_XDEV:
 2399             ll = GF_LOG_WARNING;
 2400             break;
 2401 
 2402         case NFS3ERR_NODEV:
 2403             ll = GF_LOG_WARNING;
 2404             break;
 2405 
 2406         case NFS3ERR_IO:
 2407             ll = GF_LOG_WARNING;
 2408             break;
 2409 
 2410         case NFS3ERR_NXIO:
 2411             ll = GF_LOG_WARNING;
 2412             break;
 2413 
 2414         case NFS3ERR_NOTDIR:
 2415             ll = GF_LOG_WARNING;
 2416             break;
 2417 
 2418         case NFS3ERR_ISDIR:
 2419             ll = GF_LOG_WARNING;
 2420             break;
 2421 
 2422         case NFS3ERR_INVAL:
 2423             ll = GF_LOG_WARNING;
 2424             break;
 2425 
 2426         case NFS3ERR_FBIG:
 2427             ll = GF_LOG_WARNING;
 2428             break;
 2429 
 2430         case NFS3ERR_MLINK:
 2431             ll = GF_LOG_WARNING;
 2432             break;
 2433 
 2434         case NFS3ERR_NOTEMPTY:
 2435             ll = GF_LOG_WARNING;
 2436             break;
 2437 
 2438         case NFS3ERR_SERVERFAULT:
 2439             ll = GF_LOG_WARNING;
 2440             break;
 2441 
 2442         case NFS3ERR_NOTSUPP:
 2443             ll = GF_LOG_WARNING;
 2444             break;
 2445 
 2446         case NFS3ERR_BADHANDLE:
 2447             ll = GF_LOG_WARNING;
 2448             break;
 2449 
 2450         case NFS3ERR_STALE:
 2451             ll = GF_LOG_WARNING;
 2452             break;
 2453 
 2454         default:
 2455             ll = GF_LOG_DEBUG;
 2456             break;
 2457     }
 2458 
 2459     return ll;
 2460 }
 2461 
 2462 int
 2463 nfs3_mkdir_loglevel(nfsstat3 stat)
 2464 {
 2465     int ll = GF_LOG_DEBUG;
 2466 
 2467     switch (stat) {
 2468         case NFS3ERR_NOENT:
 2469             ll = GF_LOG_WARNING;
 2470             break;
 2471 
 2472         case NFS3ERR_XDEV:
 2473             ll = GF_LOG_WARNING;
 2474             break;
 2475 
 2476         case NFS3ERR_NODEV:
 2477             ll = GF_LOG_WARNING;
 2478             break;
 2479 
 2480         case NFS3ERR_IO:
 2481             ll = GF_LOG_WARNING;
 2482             break;
 2483 
 2484         case NFS3ERR_NXIO:
 2485             ll = GF_LOG_WARNING;
 2486             break;
 2487 
 2488         case NFS3ERR_NOTDIR:
 2489             ll = GF_LOG_WARNING;
 2490             break;
 2491 
 2492         case NFS3ERR_ISDIR:
 2493             ll = GF_LOG_WARNING;
 2494             break;
 2495 
 2496         case NFS3ERR_INVAL:
 2497             ll = GF_LOG_WARNING;
 2498             break;
 2499 
 2500         case NFS3ERR_FBIG:
 2501             ll = GF_LOG_WARNING;
 2502             break;
 2503 
 2504         case NFS3ERR_MLINK:
 2505             ll = GF_LOG_WARNING;
 2506             break;
 2507 
 2508         case NFS3ERR_NOTEMPTY:
 2509             ll = GF_LOG_WARNING;
 2510             break;
 2511 
 2512         case NFS3ERR_SERVERFAULT:
 2513             ll = GF_LOG_WARNING;
 2514             break;
 2515 
 2516         case NFS3ERR_NOTSUPP:
 2517             ll = GF_LOG_WARNING;
 2518             break;
 2519 
 2520         case NFS3ERR_BADHANDLE:
 2521             ll = GF_LOG_WARNING;
 2522             break;
 2523 
 2524         case NFS3ERR_STALE:
 2525             ll = GF_LOG_WARNING;
 2526             break;
 2527 
 2528         case NFS3ERR_DQUOT:
 2529             ll = GF_LOG_WARNING;
 2530             break;
 2531 
 2532         default:
 2533             ll = GF_LOG_DEBUG;
 2534             break;
 2535     }
 2536 
 2537     return ll;
 2538 }
 2539 
 2540 int
 2541 nfs3_symlink_loglevel(nfsstat3 stat)
 2542 {
 2543     int ll = GF_LOG_DEBUG;
 2544 
 2545     switch (stat) {
 2546         case NFS3ERR_XDEV:
 2547             ll = GF_LOG_WARNING;
 2548             break;
 2549 
 2550         case NFS3ERR_NODEV:
 2551             ll = GF_LOG_WARNING;
 2552             break;
 2553 
 2554         case NFS3ERR_IO:
 2555             ll = GF_LOG_WARNING;
 2556             break;
 2557 
 2558         case NFS3ERR_NXIO:
 2559             ll = GF_LOG_WARNING;
 2560             break;
 2561 
 2562         case NFS3ERR_NOTDIR:
 2563             ll = GF_LOG_WARNING;
 2564             break;
 2565 
 2566         case NFS3ERR_ISDIR:
 2567             ll = GF_LOG_WARNING;
 2568             break;
 2569 
 2570         case NFS3ERR_INVAL:
 2571             ll = GF_LOG_WARNING;
 2572             break;
 2573 
 2574         case NFS3ERR_FBIG:
 2575             ll = GF_LOG_WARNING;
 2576             break;
 2577 
 2578         case NFS3ERR_MLINK:
 2579             ll = GF_LOG_WARNING;
 2580             break;
 2581 
 2582         case NFS3ERR_NOTEMPTY:
 2583             ll = GF_LOG_WARNING;
 2584             break;
 2585 
 2586         case NFS3ERR_SERVERFAULT:
 2587             ll = GF_LOG_WARNING;
 2588             break;
 2589 
 2590         case NFS3ERR_NOTSUPP:
 2591             ll = GF_LOG_WARNING;
 2592             break;
 2593 
 2594         case NFS3ERR_BADHANDLE:
 2595             ll = GF_LOG_WARNING;
 2596             break;
 2597 
 2598         case NFS3ERR_STALE:
 2599             ll = GF_LOG_WARNING;
 2600             break;
 2601 
 2602         case NFS3ERR_DQUOT:
 2603             ll = GF_LOG_WARNING;
 2604             break;
 2605 
 2606         default:
 2607             ll = GF_LOG_DEBUG;
 2608             break;
 2609     }
 2610 
 2611     return ll;
 2612 }
 2613 
 2614 int
 2615 nfs3_mknod_loglevel(nfsstat3 stat)
 2616 {
 2617     int ll = GF_LOG_DEBUG;
 2618 
 2619     switch (stat) {
 2620         case NFS3ERR_NOENT:
 2621             ll = GF_LOG_WARNING;
 2622             break;
 2623 
 2624         case NFS3ERR_XDEV:
 2625             ll = GF_LOG_WARNING;
 2626             break;
 2627 
 2628         case NFS3ERR_NODEV:
 2629             ll = GF_LOG_WARNING;
 2630             break;
 2631 
 2632         case NFS3ERR_IO:
 2633             ll = GF_LOG_WARNING;
 2634             break;
 2635 
 2636         case NFS3ERR_NXIO:
 2637             ll = GF_LOG_WARNING;
 2638             break;
 2639 
 2640         case NFS3ERR_NOTDIR:
 2641             ll = GF_LOG_WARNING;
 2642             break;
 2643 
 2644         case NFS3ERR_ISDIR:
 2645             ll = GF_LOG_WARNING;
 2646             break;
 2647 
 2648         case NFS3ERR_INVAL:
 2649             ll = GF_LOG_WARNING;
 2650             break;
 2651 
 2652         case NFS3ERR_FBIG:
 2653             ll = GF_LOG_WARNING;
 2654             break;
 2655 
 2656         case NFS3ERR_MLINK:
 2657             ll = GF_LOG_WARNING;
 2658             break;
 2659 
 2660         case NFS3ERR_NOTEMPTY:
 2661             ll = GF_LOG_WARNING;
 2662             break;
 2663 
 2664         case NFS3ERR_SERVERFAULT:
 2665             ll = GF_LOG_WARNING;
 2666             break;
 2667 
 2668         case NFS3ERR_NOTSUPP:
 2669             ll = GF_LOG_WARNING;
 2670             break;
 2671 
 2672         case NFS3ERR_BADHANDLE:
 2673             ll = GF_LOG_WARNING;
 2674             break;
 2675 
 2676         case NFS3ERR_STALE:
 2677             ll = GF_LOG_WARNING;
 2678             break;
 2679 
 2680         default:
 2681             ll = GF_LOG_DEBUG;
 2682             break;
 2683     }
 2684 
 2685     return ll;
 2686 }
 2687 
 2688 int
 2689 nfs3_remove_loglevel(nfsstat3 stat)
 2690 {
 2691     int ll = GF_LOG_DEBUG;
 2692 
 2693     switch (stat) {
 2694         case NFS3ERR_EXIST:
 2695             ll = GF_LOG_WARNING;
 2696             break;
 2697 
 2698         case NFS3ERR_XDEV:
 2699             ll = GF_LOG_WARNING;
 2700             break;
 2701 
 2702         case NFS3ERR_NODEV:
 2703             ll = GF_LOG_WARNING;
 2704             break;
 2705 
 2706         case NFS3ERR_IO:
 2707             ll = GF_LOG_WARNING;
 2708             break;
 2709 
 2710         case NFS3ERR_NXIO:
 2711             ll = GF_LOG_WARNING;
 2712             break;
 2713 
 2714         case NFS3ERR_NOTDIR:
 2715             ll = GF_LOG_WARNING;
 2716             break;
 2717 
 2718         case NFS3ERR_INVAL:
 2719             ll = GF_LOG_WARNING;
 2720             break;
 2721 
 2722         case NFS3ERR_NOSPC:
 2723             ll = GF_LOG_WARNING;
 2724             break;
 2725 
 2726         case NFS3ERR_FBIG:
 2727             ll = GF_LOG_WARNING;
 2728             break;
 2729 
 2730         case NFS3ERR_MLINK:
 2731             ll = GF_LOG_WARNING;
 2732             break;
 2733 
 2734         case NFS3ERR_SERVERFAULT:
 2735             ll = GF_LOG_WARNING;
 2736             break;
 2737 
 2738         case NFS3ERR_NOTSUPP:
 2739             ll = GF_LOG_WARNING;
 2740             break;
 2741 
 2742         case NFS3ERR_BADHANDLE:
 2743             ll = GF_LOG_WARNING;
 2744             break;
 2745 
 2746         case NFS3ERR_STALE:
 2747             ll = GF_LOG_WARNING;
 2748             break;
 2749 
 2750         case NFS3ERR_DQUOT:
 2751             ll = GF_LOG_WARNING;
 2752             break;
 2753 
 2754         default:
 2755             ll = GF_LOG_DEBUG;
 2756             break;
 2757     }
 2758 
 2759     return ll;
 2760 }
 2761 
 2762 int
 2763 nfs3_rmdir_loglevel(nfsstat3 stat)
 2764 {
 2765     int ll = GF_LOG_DEBUG;
 2766 
 2767     switch (stat) {
 2768         case NFS3ERR_EXIST:
 2769             ll = GF_LOG_WARNING;
 2770             break;
 2771 
 2772         case NFS3ERR_XDEV:
 2773             ll = GF_LOG_WARNING;
 2774             break;
 2775 
 2776         case NFS3ERR_NODEV:
 2777             ll = GF_LOG_WARNING;
 2778             break;
 2779 
 2780         case NFS3ERR_IO:
 2781             ll = GF_LOG_WARNING;
 2782             break;
 2783 
 2784         case NFS3ERR_NXIO:
 2785             ll = GF_LOG_WARNING;
 2786             break;
 2787 
 2788         case NFS3ERR_NOTDIR:
 2789             ll = GF_LOG_WARNING;
 2790             break;
 2791 
 2792         case NFS3ERR_INVAL:
 2793             ll = GF_LOG_WARNING;
 2794             break;
 2795 
 2796         case NFS3ERR_NOSPC:
 2797             ll = GF_LOG_WARNING;
 2798             break;
 2799 
 2800         case NFS3ERR_FBIG:
 2801             ll = GF_LOG_WARNING;
 2802             break;
 2803 
 2804         case NFS3ERR_MLINK:
 2805             ll = GF_LOG_WARNING;
 2806             break;
 2807 
 2808         case NFS3ERR_SERVERFAULT:
 2809             ll = GF_LOG_WARNING;
 2810             break;
 2811 
 2812         case NFS3ERR_NOTSUPP:
 2813             ll = GF_LOG_WARNING;
 2814             break;
 2815 
 2816         case NFS3ERR_BADHANDLE:
 2817             ll = GF_LOG_WARNING;
 2818             break;
 2819 
 2820         case NFS3ERR_STALE:
 2821             ll = GF_LOG_WARNING;
 2822             break;
 2823 
 2824         case NFS3ERR_DQUOT:
 2825             ll = GF_LOG_WARNING;
 2826             break;
 2827 
 2828         default:
 2829             ll = GF_LOG_DEBUG;
 2830             break;
 2831     }
 2832 
 2833     return ll;
 2834 }
 2835 
 2836 int
 2837 nfs3_rename_loglevel(nfsstat3 stat)
 2838 {
 2839     int ll = GF_LOG_DEBUG;
 2840 
 2841     switch (stat) {
 2842         case NFS3ERR_XDEV:
 2843             ll = GF_LOG_WARNING;
 2844             break;
 2845 
 2846         case NFS3ERR_NODEV:
 2847             ll = GF_LOG_WARNING;
 2848             break;
 2849 
 2850         case NFS3ERR_IO:
 2851             ll = GF_LOG_WARNING;
 2852             break;
 2853 
 2854         case NFS3ERR_NXIO:
 2855             ll = GF_LOG_WARNING;
 2856             break;
 2857 
 2858         case NFS3ERR_NOTDIR:
 2859             ll = GF_LOG_WARNING;
 2860             break;
 2861 
 2862         case NFS3ERR_ISDIR:
 2863             ll = GF_LOG_WARNING;
 2864             break;
 2865 
 2866         case NFS3ERR_INVAL:
 2867             ll = GF_LOG_WARNING;
 2868             break;
 2869 
 2870         case NFS3ERR_NOSPC:
 2871             ll = GF_LOG_WARNING;
 2872             break;
 2873 
 2874         case NFS3ERR_FBIG:
 2875             ll = GF_LOG_WARNING;
 2876             break;
 2877 
 2878         case NFS3ERR_MLINK:
 2879             ll = GF_LOG_WARNING;
 2880             break;
 2881 
 2882         case NFS3ERR_NOTEMPTY:
 2883             ll = GF_LOG_WARNING;
 2884             break;
 2885 
 2886         case NFS3ERR_SERVERFAULT:
 2887             ll = GF_LOG_WARNING;
 2888             break;
 2889 
 2890         case NFS3ERR_NOTSUPP:
 2891             ll = GF_LOG_WARNING;
 2892             break;
 2893 
 2894         case NFS3ERR_BADHANDLE:
 2895             ll = GF_LOG_WARNING;
 2896             break;
 2897 
 2898         case NFS3ERR_STALE:
 2899             ll = GF_LOG_WARNING;
 2900             break;
 2901 
 2902         case NFS3ERR_DQUOT:
 2903             ll = GF_LOG_WARNING;
 2904             break;
 2905 
 2906         default:
 2907             ll = GF_LOG_DEBUG;
 2908             break;
 2909     }
 2910 
 2911     return ll;
 2912 }
 2913 
 2914 int
 2915 nfs3_link_loglevel(nfsstat3 stat)
 2916 {
 2917     int ll = GF_LOG_DEBUG;
 2918 
 2919     switch (stat) {
 2920         case NFS3ERR_XDEV:
 2921             ll = GF_LOG_WARNING;
 2922             break;
 2923 
 2924         case NFS3ERR_NODEV:
 2925             ll = GF_LOG_WARNING;
 2926             break;
 2927 
 2928         case NFS3ERR_IO:
 2929             ll = GF_LOG_WARNING;
 2930             break;
 2931 
 2932         case NFS3ERR_NXIO:
 2933             ll = GF_LOG_WARNING;
 2934             break;
 2935 
 2936         case NFS3ERR_INVAL:
 2937             ll = GF_LOG_WARNING;
 2938             break;
 2939 
 2940         case NFS3ERR_FBIG:
 2941             ll = GF_LOG_WARNING;
 2942             break;
 2943 
 2944         case NFS3ERR_MLINK:
 2945             ll = GF_LOG_WARNING;
 2946             break;
 2947 
 2948         case NFS3ERR_NOTEMPTY:
 2949             ll = GF_LOG_WARNING;
 2950             break;
 2951 
 2952         case NFS3ERR_SERVERFAULT:
 2953             ll = GF_LOG_WARNING;
 2954             break;
 2955 
 2956         case NFS3ERR_NOTSUPP:
 2957             ll = GF_LOG_WARNING;
 2958             break;
 2959 
 2960         case NFS3ERR_BADHANDLE:
 2961             ll = GF_LOG_WARNING;
 2962             break;
 2963 
 2964         case NFS3ERR_STALE:
 2965             ll = GF_LOG_WARNING;
 2966             break;
 2967 
 2968         case NFS3ERR_DQUOT:
 2969             ll = GF_LOG_WARNING;
 2970             break;
 2971 
 2972         default:
 2973             ll = GF_LOG_DEBUG;
 2974             break;
 2975     }
 2976 
 2977     return ll;
 2978 }
 2979 
 2980 int
 2981 nfs3_readdir_loglevel(nfsstat3 stat)
 2982 {
 2983     int ll = GF_LOG_DEBUG;
 2984 
 2985     switch (stat) {
 2986         case NFS3ERR_NOENT:
 2987             ll = GF_LOG_WARNING;
 2988             break;
 2989 
 2990         case NFS3ERR_EXIST:
 2991             ll = GF_LOG_WARNING;
 2992             break;
 2993 
 2994         case NFS3ERR_XDEV:
 2995             ll = GF_LOG_WARNING;
 2996             break;
 2997 
 2998         case NFS3ERR_NODEV:
 2999             ll = GF_LOG_WARNING;
 3000             break;
 3001 
 3002         case NFS3ERR_IO:
 3003             ll = GF_LOG_WARNING;
 3004             break;
 3005 
 3006         case NFS3ERR_NXIO:
 3007             ll = GF_LOG_WARNING;
 3008             break;
 3009 
 3010         case NFS3ERR_NOTDIR:
 3011             ll = GF_LOG_WARNING;
 3012             break;
 3013 
 3014         case NFS3ERR_ISDIR:
 3015             ll = GF_LOG_WARNING;
 3016             break;
 3017 
 3018         case NFS3ERR_INVAL:
 3019             ll = GF_LOG_WARNING;
 3020             break;
 3021 
 3022         case NFS3ERR_NOSPC:
 3023             ll = GF_LOG_WARNING;
 3024             break;
 3025 
 3026         case NFS3ERR_ROFS:
 3027             ll = GF_LOG_WARNING;
 3028             break;
 3029 
 3030         case NFS3ERR_FBIG:
 3031             ll = GF_LOG_WARNING;
 3032             break;
 3033 
 3034         case NFS3ERR_MLINK:
 3035             ll = GF_LOG_WARNING;
 3036             break;
 3037 
 3038         case NFS3ERR_NAMETOOLONG:
 3039             ll = GF_LOG_WARNING;
 3040             break;
 3041 
 3042         case NFS3ERR_NOTEMPTY:
 3043             ll = GF_LOG_WARNING;
 3044             break;
 3045 
 3046         case NFS3ERR_SERVERFAULT:
 3047             ll = GF_LOG_WARNING;
 3048             break;
 3049 
 3050         case NFS3ERR_NOTSUPP:
 3051             ll = GF_LOG_WARNING;
 3052             break;
 3053 
 3054         case NFS3ERR_BADHANDLE:
 3055             ll = GF_LOG_WARNING;
 3056             break;
 3057 
 3058         case NFS3ERR_STALE:
 3059             ll = GF_LOG_WARNING;
 3060             break;
 3061 
 3062         case NFS3ERR_DQUOT:
 3063             ll = GF_LOG_WARNING;
 3064             break;
 3065 
 3066         default:
 3067             ll = GF_LOG_DEBUG;
 3068             break;
 3069     }
 3070 
 3071     return ll;
 3072 }
 3073 
 3074 int
 3075 nfs3_fsstat_loglevel(nfsstat3 stat)
 3076 {
 3077     int ll = GF_LOG_DEBUG;
 3078 
 3079     switch (stat) {
 3080         case NFS3ERR_PERM:
 3081             ll = GF_LOG_WARNING;
 3082             break;
 3083 
 3084         case NFS3ERR_NOENT:
 3085             ll = GF_LOG_WARNING;
 3086             break;
 3087 
 3088         case NFS3ERR_ACCES:
 3089             ll = GF_LOG_WARNING;
 3090             break;
 3091 
 3092         case NFS3ERR_EXIST:
 3093             ll = GF_LOG_WARNING;
 3094             break;
 3095 
 3096         case NFS3ERR_XDEV:
 3097             ll = GF_LOG_WARNING;
 3098             break;
 3099 
 3100         case NFS3ERR_NODEV:
 3101             ll = GF_LOG_WARNING;
 3102             break;
 3103 
 3104         case NFS3ERR_IO:
 3105             ll = GF_LOG_WARNING;
 3106             break;
 3107 
 3108         case NFS3ERR_NXIO:
 3109             ll = GF_LOG_WARNING;
 3110             break;
 3111 
 3112         case NFS3ERR_NOTDIR:
 3113             ll = GF_LOG_WARNING;
 3114             break;
 3115 
 3116         case NFS3ERR_ISDIR:
 3117             ll = GF_LOG_WARNING;
 3118             break;
 3119 
 3120         case NFS3ERR_INVAL:
 3121             ll = GF_LOG_WARNING;
 3122             break;
 3123 
 3124         case NFS3ERR_NOSPC:
 3125             ll = GF_LOG_WARNING;
 3126             break;
 3127 
 3128         case NFS3ERR_ROFS:
 3129             ll = GF_LOG_WARNING;
 3130             break;
 3131 
 3132         case NFS3ERR_FBIG:
 3133             ll = GF_LOG_WARNING;
 3134             break;
 3135 
 3136         case NFS3ERR_MLINK:
 3137             ll = GF_LOG_WARNING;
 3138             break;
 3139 
 3140         case NFS3ERR_NAMETOOLONG:
 3141             ll = GF_LOG_WARNING;
 3142             break;
 3143 
 3144         case NFS3ERR_NOTEMPTY:
 3145             ll = GF_LOG_WARNING;
 3146             break;
 3147 
 3148         case NFS3ERR_SERVERFAULT:
 3149             ll = GF_LOG_WARNING;
 3150             break;
 3151 
 3152         case NFS3ERR_NOTSUPP:
 3153             ll = GF_LOG_WARNING;
 3154             break;
 3155 
 3156         case NFS3ERR_BADHANDLE:
 3157             ll = GF_LOG_WARNING;
 3158             break;
 3159 
 3160         case NFS3ERR_STALE:
 3161             ll = GF_LOG_WARNING;
 3162             break;
 3163 
 3164         case NFS3ERR_DQUOT:
 3165             ll = GF_LOG_WARNING;
 3166             break;
 3167 
 3168         default:
 3169             ll = GF_LOG_DEBUG;
 3170             break;
 3171     }
 3172 
 3173     return ll;
 3174 }
 3175 
 3176 struct nfs3op_str {
 3177     int op;
 3178     char str[100];
 3179 };
 3180 
 3181 struct nfs3op_str nfs3op_strings[] = {
 3182     {NFS3_NULL, "NULL"},         {NFS3_GETATTR, "GETATTR"},
 3183     {NFS3_SETATTR, "SETATTR"},   {NFS3_LOOKUP, "LOOKUP"},
 3184     {NFS3_ACCESS, "ACCESS"},     {NFS3_READLINK, "READLINK"},
 3185     {NFS3_READ, "READ"},         {NFS3_WRITE, "WRITE"},
 3186     {NFS3_CREATE, "CREATE"},     {NFS3_MKDIR, "MKDIR"},
 3187     {NFS3_SYMLINK, "SYMLINK"},   {NFS3_MKNOD, "MKNOD"},
 3188     {NFS3_REMOVE, "REMOVE"},     {NFS3_RMDIR, "RMDIR"},
 3189     {NFS3_RENAME, "RENAME"},     {NFS3_LINK, "LINK"},
 3190     {NFS3_READDIR, "READDIR"},   {NFS3_READDIRP, "READDIRP"},
 3191     {NFS3_FSSTAT, "FSSTAT"},     {NFS3_FSINFO, "FSINFO"},
 3192     {NFS3_PATHCONF, "PATHCONF"}, {NFS3_COMMIT, "COMMIT"},
 3193 };
 3194 
 3195 int
 3196 nfs3_loglevel(int nfs_op, nfsstat3 stat)
 3197 {
 3198     int ll = GF_LOG_DEBUG;
 3199 
 3200     switch (nfs_op) {
 3201         case NFS3_GETATTR:
 3202             ll = nfs3_getattr_loglevel(stat);
 3203             break;
 3204 
 3205         case NFS3_SETATTR:
 3206             ll = nfs3_setattr_loglevel(stat);
 3207             break;
 3208 
 3209         case NFS3_LOOKUP:
 3210             ll = nfs3_lookup_loglevel(stat);
 3211             break;
 3212 
 3213         case NFS3_ACCESS:
 3214             ll = nfs3_access_loglevel(stat);
 3215             break;
 3216 
 3217         case NFS3_READLINK:
 3218             ll = nfs3_readlink_loglevel(stat);
 3219             break;
 3220 
 3221         case NFS3_READ:
 3222             ll = nfs3_read_loglevel(stat);
 3223             break;
 3224 
 3225         case NFS3_WRITE:
 3226             ll = nfs3_write_loglevel(stat);
 3227             break;
 3228 
 3229         case NFS3_CREATE:
 3230             ll = nfs3_create_loglevel(stat);
 3231             break;
 3232 
 3233         case NFS3_MKDIR:
 3234             ll = nfs3_mkdir_loglevel(stat);
 3235             break;
 3236 
 3237         case NFS3_SYMLINK:
 3238             ll = nfs3_symlink_loglevel(stat);
 3239             break;
 3240 
 3241         case NFS3_MKNOD:
 3242             ll = nfs3_mknod_loglevel(stat);
 3243             break;
 3244 
 3245         case NFS3_REMOVE:
 3246             ll = nfs3_remove_loglevel(stat);
 3247             break;
 3248 
 3249         case NFS3_RMDIR:
 3250             ll = nfs3_rmdir_loglevel(stat);
 3251             break;
 3252 
 3253         case NFS3_RENAME:
 3254             ll = nfs3_rename_loglevel(stat);
 3255             break;
 3256 
 3257         case NFS3_LINK:
 3258             ll = nfs3_link_loglevel(stat);
 3259             break;
 3260 
 3261         case NFS3_READDIR:
 3262             ll = nfs3_readdir_loglevel(stat);
 3263             break;
 3264 
 3265         case NFS3_READDIRP:
 3266             ll = nfs3_readdir_loglevel(stat);
 3267             break;
 3268 
 3269         case NFS3_FSSTAT:
 3270             ll = nfs3_fsstat_loglevel(stat);
 3271             break;
 3272 
 3273         case NFS3_FSINFO:
 3274             ll = nfs3_fsstat_loglevel(stat);
 3275             break;
 3276 
 3277         case NFS3_PATHCONF:
 3278             ll = nfs3_fsstat_loglevel(stat);
 3279             break;
 3280 
 3281         case NFS3_COMMIT:
 3282             ll = nfs3_write_loglevel(stat);
 3283             break;
 3284 
 3285         default:
 3286             ll = GF_LOG_DEBUG;
 3287             break;
 3288     }
 3289 
 3290     return ll;
 3291 }
 3292 
 3293 void
 3294 nfs3_log_common_res(uint32_t xid, int op, nfsstat3 stat, int pstat,
 3295                     const char *path)
 3296 {
 3297     char errstr[1024];
 3298     int ll = nfs3_loglevel(op, stat);
 3299 
 3300     if (THIS->ctx->log.loglevel < ll)
 3301         return;
 3302     nfs3_stat_to_errstr(xid, nfs3op_strings[op].str, stat, pstat, errstr,
 3303                         sizeof(errstr));
 3304     if (ll == GF_LOG_DEBUG)
 3305         gf_msg_debug(GF_NFS3, 0, "%s => (%s)", path, errstr);
 3306     else
 3307         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR, "%s => (%s)", path,
 3308                errstr);
 3309 }
 3310 
 3311 void
 3312 nfs3_log_readlink_res(uint32_t xid, nfsstat3 stat, int pstat, char *linkpath,
 3313                       const char *path)
 3314 {
 3315     char errstr[1024];
 3316     int ll = nfs3_loglevel(NFS3_READLINK, stat);
 3317 
 3318     if (THIS->ctx->log.loglevel < ll)
 3319         return;
 3320 
 3321     nfs3_stat_to_errstr(xid, "READLINK", stat, pstat, errstr, sizeof(errstr));
 3322     if (ll == GF_LOG_DEBUG)
 3323         gf_msg_debug(GF_NFS3, 0, "%s => (%s), target: %s", path, errstr,
 3324                      linkpath);
 3325     else
 3326         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR, "%s => (%s) target: %s",
 3327                path, errstr, linkpath);
 3328 }
 3329 
 3330 void
 3331 nfs3_log_read_res(uint32_t xid, nfsstat3 stat, int pstat, count3 count,
 3332                   int is_eof, struct iovec *vec, int32_t veccount,
 3333                   const char *path)
 3334 {
 3335     char errstr[1024];
 3336     int ll = GF_LOG_DEBUG;
 3337 
 3338     ll = nfs3_loglevel(NFS3_READ, stat);
 3339     if (THIS->ctx->log.loglevel < ll)
 3340         return;
 3341     nfs3_stat_to_errstr(xid, "READ", stat, pstat, errstr, sizeof(errstr));
 3342     if (vec)
 3343         if (ll == GF_LOG_DEBUG)
 3344             gf_msg_debug(GF_NFS3, 0,
 3345                          "%s => (%s), count: %" PRIu32
 3346                          ", is_eof:"
 3347                          " %d, vector: count: %d, len: %zd",
 3348                          path, errstr, count, is_eof, veccount, vec->iov_len);
 3349         else
 3350             gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3351                    "%s => (%s), count: %" PRIu32
 3352                    ", is_eof:"
 3353                    " %d, vector: count: %d, len: %zd",
 3354                    path, errstr, count, is_eof, veccount, vec->iov_len);
 3355     else if (ll == GF_LOG_DEBUG)
 3356         gf_msg_debug(GF_NFS3, 0,
 3357                      "%s => (%s), count: %" PRIu32
 3358                      ", is_eof:"
 3359                      " %d",
 3360                      path, errstr, count, is_eof);
 3361     else
 3362         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3363                "%s => (%s), count: %" PRIu32
 3364                ", is_eof:"
 3365                " %d",
 3366                path, errstr, count, is_eof);
 3367 }
 3368 
 3369 void
 3370 nfs3_log_write_res(uint32_t xid, nfsstat3 stat, int pstat, count3 count,
 3371                    int stable, uint64_t wverf, const char *path)
 3372 {
 3373     char errstr[1024];
 3374     int ll = nfs3_loglevel(NFS3_WRITE, stat);
 3375 
 3376     if (THIS->ctx->log.loglevel < ll)
 3377         return;
 3378 
 3379     nfs3_stat_to_errstr(xid, "WRITE", stat, pstat, errstr, sizeof(errstr));
 3380     if (ll == GF_LOG_DEBUG)
 3381         gf_msg_debug(GF_NFS3, 0,
 3382                      "%s => (%s), count: %" PRIu32
 3383                      ", %s,wverf: "
 3384                      "%" PRIu64,
 3385                      path, errstr, count,
 3386                      (stable == UNSTABLE) ? "UNSTABLE" : "STABLE", wverf);
 3387     else
 3388         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3389                "%s => (%s), count: %" PRIu32 ", %s,wverf: %" PRIu64, path,
 3390                errstr, count, (stable == UNSTABLE) ? "UNSTABLE" : "STABLE",
 3391                wverf);
 3392 }
 3393 
 3394 void
 3395 nfs3_log_newfh_res(uint32_t xid, int op, nfsstat3 stat, int pstat,
 3396                    struct nfs3_fh *newfh, const char *path)
 3397 {
 3398     char errstr[1024];
 3399     char fhstr[1024];
 3400     int ll = nfs3_loglevel(op, stat);
 3401 
 3402     if (THIS->ctx->log.loglevel < ll)
 3403         return;
 3404     nfs3_stat_to_errstr(xid, nfs3op_strings[op].str, stat, pstat, errstr,
 3405                         sizeof(errstr));
 3406     nfs3_fh_to_str(newfh, fhstr, sizeof(fhstr));
 3407 
 3408     if (ll == GF_LOG_DEBUG)
 3409         gf_msg_debug(GF_NFS3, 0, "%s => (%s), %s", path, errstr, fhstr);
 3410     else
 3411         gf_msg(GF_NFS3, nfs3_loglevel(op, stat), errno, NFS_MSG_STAT_ERROR,
 3412                "%s => (%s), %s", path, errstr, fhstr);
 3413 }
 3414 
 3415 void
 3416 nfs3_log_readdir_res(uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,
 3417                      count3 count, int is_eof, const char *path)
 3418 {
 3419     char errstr[1024];
 3420     int ll = nfs3_loglevel(NFS3_READDIR, stat);
 3421 
 3422     if (THIS->ctx->log.loglevel < ll)
 3423         return;
 3424     nfs3_stat_to_errstr(xid, "READDIR", stat, pstat, errstr, sizeof(errstr));
 3425     if (ll == GF_LOG_DEBUG)
 3426         gf_msg_debug(GF_NFS3, 0,
 3427                      "%s => (%s), count: %" PRIu32 ", cverf: %" PRIu64
 3428                      ", is_eof: %d",
 3429                      path, errstr, count, cverf, is_eof);
 3430     else
 3431         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3432                "%s => (%s), count: %" PRIu32 ", cverf: %" PRIu64 ", is_eof: %d",
 3433                path, errstr, count, cverf, is_eof);
 3434 }
 3435 
 3436 void
 3437 nfs3_log_readdirp_res(uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,
 3438                       count3 dircount, count3 maxcount, int is_eof,
 3439                       const char *path)
 3440 {
 3441     char errstr[1024];
 3442     int ll = nfs3_loglevel(NFS3_READDIRP, stat);
 3443 
 3444     if (THIS->ctx->log.loglevel < ll)
 3445         return;
 3446     nfs3_stat_to_errstr(xid, "READDIRPLUS", stat, pstat, errstr,
 3447                         sizeof(errstr));
 3448     if (ll == GF_LOG_DEBUG)
 3449         gf_msg_debug(GF_NFS3, 0,
 3450                      "%s => (%s), dircount: %" PRIu32 ", maxcount: %" PRIu32
 3451                      ", cverf: %" PRIu64 ", is_eof: %d",
 3452                      path, errstr, dircount, maxcount, cverf, is_eof);
 3453     else
 3454         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3455                "%s => (%s), dircount: %" PRIu32 ", maxcount: %" PRIu32
 3456                ", cverf: %" PRIu64 ", is_eof: %d",
 3457                path, errstr, dircount, maxcount, cverf, is_eof);
 3458 }
 3459 
 3460 void
 3461 nfs3_log_commit_res(uint32_t xid, nfsstat3 stat, int pstat, uint64_t wverf,
 3462                     const char *path)
 3463 {
 3464     char errstr[1024];
 3465     int ll = nfs3_loglevel(NFS3_COMMIT, stat);
 3466 
 3467     if (THIS->ctx->log.loglevel < ll)
 3468         return;
 3469     nfs3_stat_to_errstr(xid, "COMMIT", stat, pstat, errstr, sizeof(errstr));
 3470     if (ll == GF_LOG_DEBUG)
 3471         gf_msg_debug(GF_NFS3, 0, "%s => (%s), wverf: %" PRIu64, path, errstr,
 3472                      wverf);
 3473     else
 3474         gf_msg(GF_NFS3, ll, errno, NFS_MSG_STAT_ERROR,
 3475                "%s => (%s), wverf: %" PRIu64, path, errstr, wverf);
 3476 }
 3477 
 3478 void
 3479 nfs3_log_readdir_call(uint32_t xid, struct nfs3_fh *fh, count3 dircount,
 3480                       count3 maxcount)
 3481 {
 3482     char fhstr[1024];
 3483 
 3484     if (THIS->ctx->log.loglevel < GF_LOG_DEBUG)
 3485         return;
 3486 
 3487     nfs3_fh_to_str(fh, fhstr, sizeof(fhstr));
 3488 
 3489     if (maxcount == 0)
 3490         gf_msg_debug(GF_NFS3, 0,
 3491                      "XID: %x, READDIR: args: %s,"
 3492                      " count: %d",
 3493                      xid, fhstr, (uint32_t)dircount);
 3494     else
 3495         gf_msg_debug(GF_NFS3, 0,
 3496                      "XID: %x, READDIRPLUS: args: %s,"
 3497                      " dircount: %d, maxcount: %d",
 3498                      xid, fhstr, (uint32_t)dircount, (uint32_t)maxcount);
 3499 }
 3500 
 3501 int
 3502 nfs3_fh_resolve_inode_done(nfs3_call_state_t *cs, inode_t *inode)
 3503 {
 3504     int ret = -EFAULT;
 3505 
 3506     if ((!cs) || (!inode))
 3507         return ret;
 3508 
 3509     gf_msg_trace(GF_NFS3, 0, "FH inode resolved");
 3510     ret = nfs_inode_loc_fill(inode, &cs->resolvedloc, NFS_RESOLVE_EXIST);
 3511     if (ret < 0) {
 3512         gf_msg(GF_NFS3, GF_LOG_ERROR, -ret, NFS_MSG_INODE_LOC_FILL_ERROR,
 3513                "inode loc fill failed");
 3514         goto err;
 3515     }
 3516 
 3517     nfs3_call_resume(cs);
 3518 
 3519 err:
 3520     return ret;
 3521 }
 3522 
 3523 int32_t
 3524 nfs3_fh_resolve_entry_lookup_cbk(call_frame_t *frame, void *cookie,
 3525                                  xlator_t *this, int32_t op_ret,
 3526                                  int32_t op_errno, inode_t *inode,
 3527                                  struct iatt *buf, dict_t *xattr,
 3528                                  struct iatt *postparent)
 3529 {
 3530     nfs3_call_state_t *cs = NULL;
 3531     inode_t *linked_inode = NULL;
 3532 
 3533     cs = frame->local;
 3534     cs->resolve_ret = op_ret;
 3535     cs->resolve_errno = op_errno;
 3536 
 3537     if (op_ret == -1) {
 3538         if (op_errno == ENOENT) {
 3539             gf_msg_trace(GF_NFS3, 0, "Lookup failed: %s: %s",
 3540                          cs->resolvedloc.path, strerror(op_errno));
 3541         } else {
 3542             gf_msg(GF_NFS3, GF_LOG_ERROR, op_errno, NFS_MSG_LOOKUP_FAIL,
 3543                    "Lookup failed: %s: %s", cs->resolvedloc.path,
 3544                    strerror(op_errno));
 3545         }
 3546         goto err;
 3547     } else
 3548         gf_msg_trace(GF_NFS3, 0, "Entry looked up: %s", cs->resolvedloc.path);
 3549 
 3550     memcpy(&cs->stbuf, buf, sizeof(*buf));
 3551     memcpy(&cs->postparent, postparent, sizeof(*postparent));
 3552     linked_inode = inode_link(inode, cs->resolvedloc.parent,
 3553                               cs->resolvedloc.name, buf);
 3554     if (linked_inode) {
 3555         nfs_fix_generation(this, linked_inode);
 3556         inode_lookup(linked_inode);
 3557         inode_unref(cs->resolvedloc.inode);
 3558         cs->resolvedloc.inode = linked_inode;
 3559     } else {
 3560         /* nfs3_fh_resolve_entry_hard() use to resolve entire path if needed.
 3561          * So the ctx for inode obtained from here need to set properly,
 3562          * otherwise it may result in a crash.
 3563          */
 3564         nfs_fix_generation(this, inode);
 3565     }
 3566 err:
 3567     nfs3_call_resume(cs);
 3568     return 0;
 3569 }
 3570 
 3571 int32_t
 3572 nfs3_fh_resolve_inode_lookup_cbk(call_frame_t *frame, void *cookie,
 3573                                  xlator_t *this, int32_t op_ret,
 3574                                  int32_t op_errno, inode_t *inode,
 3575                                  struct iatt *buf, dict_t *xattr,
 3576                                  struct iatt *postparent)
 3577 {
 3578     nfs3_call_state_t *cs = NULL;
 3579     inode_t *linked_inode = NULL;
 3580 
 3581     cs = frame->local;
 3582     cs->resolve_ret = op_ret;
 3583     cs->resolve_errno = op_errno;
 3584 
 3585     if (op_ret == -1) {
 3586         if (op_errno == ENOENT) {
 3587             gf_msg_trace(GF_NFS3, 0, "Lookup failed: %s: %s",
 3588                          cs->resolvedloc.path, strerror(op_errno));
 3589         } else {
 3590             gf_msg(GF_NFS3, GF_LOG_ERROR, op_errno, NFS_MSG_LOOKUP_FAIL,
 3591                    "Lookup failed: %s: %s", cs->resolvedloc.path,
 3592                    strerror(op_errno));
 3593         }
 3594         nfs3_call_resume(cs);
 3595         goto err;
 3596     }
 3597 
 3598     memcpy(&cs->stbuf, buf, sizeof(*buf));
 3599     memcpy(&cs->postparent, buf, sizeof(*postparent));
 3600     linked_inode = inode_link(inode, cs->resolvedloc.parent,
 3601                               cs->resolvedloc.name, buf);
 3602     if (linked_inode) {
 3603         nfs_fix_generation(this, linked_inode);
 3604         inode_lookup(linked_inode);
 3605         inode_unref(cs->resolvedloc.inode);
 3606         cs->resolvedloc.inode = linked_inode;
 3607     }
 3608 
 3609     /* If it is an entry lookup and we landed in the callback for hard
 3610      * inode resolution, it means the parent inode was not available and
 3611      * had to be resolved first. Now that is done, lets head back into
 3612      * entry resolution.
 3613      */
 3614     if (cs->resolventry)
 3615         nfs3_fh_resolve_entry_hard(cs);
 3616     else
 3617         nfs3_call_resume(cs);
 3618 err:
 3619     return 0;
 3620 }
 3621 
 3622 /* Needs no extra argument since it knows that the fh to be resolved is in
 3623  * resolvefh and that it needs to start looking from the root.
 3624  */
 3625 int
 3626 nfs3_fh_resolve_inode_hard(nfs3_call_state_t *cs)
 3627 {
 3628     int ret = -EFAULT;
 3629     nfs_user_t nfu = {
 3630         0,
 3631     };
 3632 
 3633     if (!cs)
 3634         return ret;
 3635 
 3636     gf_msg_trace(GF_NFS3, 0, "FH hard resolution for: gfid 0x%s",
 3637                  uuid_utoa(cs->resolvefh.gfid));
 3638     cs->hardresolved = 1;
 3639     nfs_loc_wipe(&cs->resolvedloc);
 3640     ret = nfs_gfid_loc_fill(cs->vol->itable, cs->resolvefh.gfid,
 3641                             &cs->resolvedloc, NFS_RESOLVE_CREATE);
 3642     if (ret < 0) {
 3643         gf_msg(GF_NFS3, GF_LOG_ERROR, -ret, NFS_MSG_INODE_LOC_FILL_ERROR,
 3644                "Failed to fill loc using gfid: "
 3645                "%s",
 3646                strerror(-ret));
 3647         goto out;
 3648     }
 3649 
 3650     nfs_user_root_create(&nfu);
 3651     ret = nfs_lookup(cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
 3652                      nfs3_fh_resolve_inode_lookup_cbk, cs);
 3653 
 3654 out:
 3655     return ret;
 3656 }
 3657 
 3658 int
 3659 nfs3_fh_resolve_entry_hard(nfs3_call_state_t *cs)
 3660 {
 3661     int ret = -EFAULT;
 3662     nfs_user_t nfu = {
 3663         0,
 3664     };
 3665     gf_boolean_t freshlookup = _gf_false;
 3666 
 3667     if (!cs)
 3668         return ret;
 3669 
 3670     nfs_loc_wipe(&cs->resolvedloc);
 3671     nfs_user_root_create(&nfu);
 3672     gf_msg_trace(GF_NFS3, 0,
 3673                  "FH hard resolution: gfid: %s "
 3674                  ", entry: %s",
 3675                  uuid_utoa(cs->resolvefh.gfid), cs->resolventry);
 3676 
 3677     ret = nfs_entry_loc_fill(cs->nfsx, cs->vol->itable, cs->resolvefh.gfid,
 3678                              cs->resolventry, &cs->resolvedloc,
 3679                              NFS_RESOLVE_CREATE, &freshlookup);
 3680 
 3681     if (ret == -2) {
 3682         gf_msg_trace(GF_NFS3, 0, "Entry needs lookup: %s",
 3683                      cs->resolvedloc.path);
 3684         /* If the NFS op is lookup, let the resume callback
 3685          * handle the sending of the lookup fop. Similarly,
 3686          * if the NFS op is create, let the create call
 3687          * go ahead in the resume callback so that an EEXIST gets
 3688          * handled at posix without an extra fop at this point.
 3689          */
 3690         if (freshlookup &&
 3691             (nfs3_lookup_op(cs) ||
 3692              (nfs3_create_op(cs) && !nfs3_create_exclusive_op(cs)))) {
 3693             cs->lookuptype = GF_NFS3_FRESH;
 3694             cs->resolve_ret = 0;
 3695             cs->hardresolved = 0;
 3696             nfs3_call_resume(cs);
 3697         } else {
 3698             cs->hardresolved = 1;
 3699             nfs_lookup(cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
 3700                        nfs3_fh_resolve_entry_lookup_cbk, cs);
 3701         }
 3702         ret = 0;
 3703     } else if (ret == -1) {
 3704         gf_msg_trace(GF_NFS3, 0, "Entry needs parent lookup: %s",
 3705                      cs->resolvedloc.path);
 3706         ret = nfs3_fh_resolve_inode_hard(cs);
 3707     } else if (ret == 0) {
 3708         cs->resolve_ret = 0;
 3709         nfs3_call_resume(cs);
 3710     }
 3711 
 3712     return ret;
 3713 }
 3714 
 3715 int
 3716 nfs3_fh_resolve_inode(nfs3_call_state_t *cs)
 3717 {
 3718     inode_t *inode = NULL;
 3719     int ret = -EFAULT;
 3720     xlator_t *this = NULL;
 3721 
 3722     if (!cs)
 3723         return ret;
 3724 
 3725     this = cs->nfsx;
 3726     gf_msg_trace(GF_NFS3, 0, "FH needs inode resolution");
 3727     gf_uuid_copy(cs->resolvedloc.gfid, cs->resolvefh.gfid);
 3728 
 3729     inode = inode_find(cs->vol->itable, cs->resolvefh.gfid);
 3730     if (!inode || inode_ctx_get(inode, this, NULL))
 3731         ret = nfs3_fh_resolve_inode_hard(cs);
 3732     else
 3733         ret = nfs3_fh_resolve_inode_done(cs, inode);
 3734 
 3735     if (inode)
 3736         inode_unref(inode);
 3737 
 3738     return ret;
 3739 }
 3740 
 3741 int
 3742 nfs3_fh_resolve_entry(nfs3_call_state_t *cs)
 3743 {
 3744     int ret = -EFAULT;
 3745 
 3746     if (!cs)
 3747         return ret;
 3748 
 3749     return nfs3_fh_resolve_entry_hard(cs);
 3750 }
 3751 
 3752 int
 3753 nfs3_fh_resolve_resume(nfs3_call_state_t *cs)
 3754 {
 3755     int ret = -EFAULT;
 3756 
 3757     if (!cs)
 3758         return ret;
 3759 
 3760     if (cs->resolve_ret < 0)
 3761         goto err_resume_call;
 3762 
 3763     if (!cs->resolventry)
 3764         ret = nfs3_fh_resolve_inode(cs);
 3765     else
 3766         ret = nfs3_fh_resolve_entry(cs);
 3767 
 3768 err_resume_call:
 3769     if (ret < 0) {
 3770         cs->resolve_ret = -1;
 3771         cs->resolve_errno = EFAULT;
 3772         nfs3_call_resume(cs);
 3773         ret = 0;
 3774     }
 3775 
 3776     return ret;
 3777 }
 3778 
 3779 int32_t
 3780 nfs3_fh_resolve_root_lookup_cbk(call_frame_t *frame, void *cookie,
 3781                                 xlator_t *this, int32_t op_ret,
 3782                                 int32_t op_errno, inode_t *inode,
 3783                                 struct iatt *buf, dict_t *xattr,
 3784                                 struct iatt *postparent)
 3785 {
 3786     nfs3_call_state_t *cs = NULL;
 3787 
 3788     cs = frame->local;
 3789     cs->resolve_ret = op_ret;
 3790     cs->resolve_errno = op_errno;
 3791 
 3792     if (op_ret == -1) {
 3793         gf_msg(GF_NFS3, GF_LOG_ERROR, op_errno, NFS_MSG_LOOKUP_ROOT_FAIL,
 3794                "Root lookup failed: %s", strerror(op_errno));
 3795         goto err;
 3796     } else
 3797         gf_msg_trace(GF_NFS3, 0, "Root looked up: %s", cs->resolvedloc.path);
 3798 
 3799     nfs3_set_root_looked_up(cs->nfs3state, &cs->resolvefh);
 3800 err:
 3801     nfs3_fh_resolve_resume(cs);
 3802     return 0;
 3803 }
 3804 
 3805 int
 3806 nfs3_fh_resolve_root(nfs3_call_state_t *cs)
 3807 {
 3808     int ret = -EFAULT;
 3809     nfs_user_t nfu = {
 3810         0,
 3811     };
 3812 
 3813     if (!cs)
 3814         return ret;
 3815 
 3816     if (nfs3_is_root_looked_up(cs->nfs3state, &cs->resolvefh)) {
 3817         ret = nfs3_fh_resolve_resume(cs);
 3818         goto out;
 3819     }
 3820 
 3821     nfs_user_root_create(&nfu);
 3822     gf_msg_trace(GF_NFS3, 0, "Root needs lookup");
 3823     ret = nfs_root_loc_fill(cs->vol->itable, &cs->resolvedloc);
 3824     if (ret < 0) {
 3825         gf_msg(GF_NFS3, GF_LOG_ERROR, -ret, NFS_MSG_LOOKUP_ROOT_FAIL,
 3826                "Failed to lookup root from itable: %s", strerror(-ret));
 3827         goto out;
 3828     }
 3829 
 3830     ret = nfs_lookup(cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
 3831                      nfs3_fh_resolve_root_lookup_cbk, cs);
 3832 
 3833 out:
 3834     return ret;
 3835 }
 3836 
 3837 /**
 3838  * __nfs3_fh_auth_get_peer -- Get a peer name from the rpc request object
 3839  *
 3840  * @peer: Char * to write to
 3841  * @req : The request to get host/peer from
 3842  */
 3843 int
 3844 __nfs3_fh_auth_get_peer(const rpcsvc_request_t *req, char *peer)
 3845 {
 3846     struct sockaddr_storage sastorage = {
 3847         0,
 3848     };
 3849     rpc_transport_t *trans = NULL;
 3850     int ret = 0;
 3851 
 3852     /* Why do we pass in the peer here and then
 3853      * store it rather than malloc() and return a char * ? We want to avoid
 3854      * heap allocations in the IO path as much as possible for speed
 3855      * so we try to keep all allocations on the stack.
 3856      */
 3857     trans = rpcsvc_request_transport(req);
 3858     ret = rpcsvc_transport_peeraddr(trans, peer, RPCSVC_PEER_STRLEN, &sastorage,
 3859                                     sizeof(sastorage));
 3860     if (ret != 0) {
 3861         gf_msg(GF_NFS3, GF_LOG_WARNING, 0, NFS_MSG_GET_PEER_ADDR_FAIL,
 3862                "Failed to get peer addr: %s", gai_strerror(ret));
 3863     }
 3864     return ret;
 3865 }
 3866 
 3867 /*
 3868  * nfs3_fh_auth_nfsop () -- Checks if an nfsop is authorized.
 3869  *
 3870  * @cs: The NFS call state containing all the relevant information
 3871  *
 3872  * @return: 0 if authorized
 3873  *          -EACCES for completely unauthorized fop
 3874  *          -EROFS  for unauthorized write operations (rm, mkdir, write)
 3875  */
 3876 int
 3877 nfs3_fh_auth_nfsop(nfs3_call_state_t *cs, gf_boolean_t is_write_op)
 3878 {
 3879     struct nfs_state *nfs = NULL;
 3880     struct mount3_state *ms = NULL;
 3881 
 3882     nfs = (struct nfs_state *)cs->nfsx->private;
 3883     ms = (struct mount3_state *)nfs->mstate;
 3884     return mnt3_authenticate_request(ms, cs->req, &cs->resolvefh, NULL, NULL,
 3885                                      NULL, NULL, is_write_op);
 3886 }
 3887 
 3888 int
 3889 nfs3_fh_resolve_and_resume(nfs3_call_state_t *cs, struct nfs3_fh *fh,
 3890                            char *entry, nfs3_resume_fn_t resum_fn)
 3891 {
 3892     int ret = -EFAULT;
 3893 
 3894     if ((!cs) || (!fh))
 3895         return ret;
 3896 
 3897     cs->resume_fn = resum_fn;
 3898     cs->resolvefh = *fh;
 3899     cs->hashidx = 0;
 3900 
 3901     /* Check if the resolution is:
 3902      * a. fh resolution
 3903      *
 3904      * or
 3905      *
 3906      * b. (fh, basename) resolution
 3907      */
 3908     if (entry) { /* b */
 3909         cs->resolventry = gf_strdup(entry);
 3910         if (!cs->resolventry)
 3911             goto err;
 3912     }
 3913 
 3914     ret = nfs3_fh_resolve_root(cs);
 3915 err:
 3916     return ret;
 3917 }