diff options
Diffstat (limited to 'xlators/nfs/server/src')
| -rw-r--r-- | xlators/nfs/server/src/acl3.c | 49 | ||||
| -rw-r--r-- | xlators/nfs/server/src/mount3.c | 72 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs-common.c | 2 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs-inodes.c | 4 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs-mem-types.h | 1 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs3-fh.c | 12 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs3-fh.h | 2 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs3-helpers.c | 129 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nfs3.c | 60 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nlm4.c | 12 | ||||
| -rw-r--r-- | xlators/nfs/server/src/nlmcbk_svc.c | 10 | 
11 files changed, 195 insertions, 158 deletions
diff --git a/xlators/nfs/server/src/acl3.c b/xlators/nfs/server/src/acl3.c index ed60775ab32..9e98124fe57 100644 --- a/xlators/nfs/server/src/acl3.c +++ b/xlators/nfs/server/src/acl3.c @@ -113,8 +113,10 @@ nfs3_fh_to_xlator (struct nfs3_state *nfs3, struct nfs3_fh *fh);                          xlatorp = nfs3_fh_to_xlator (cst->nfs3state,    \                                                       &cst->resolvefh);  \                          uuid_unparse (cst->resolvefh.gfid, gfid);       \ -                        sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\ -                        xlatorp ? xlatorp->name : "ERR", gfid);         \ +                        snprintf (buf, sizeof (buf), "(%s) %s : %s",             \ +                                  trans->peerinfo.identifier,           \ +                                  xlatorp ? xlatorp->name : "ERR",      \ +                                  gfid);                                \                          gf_log (GF_ACL, GF_LOG_ERROR, "Unable to resolve FH"\                                  ": %s", buf);                           \                          nfstat = nfs3_errno_to_nfsstat3 (cst->resolve_errno);\ @@ -228,10 +230,13 @@ acl3_getacl_cbk (call_frame_t *frame, void *cookie, xlator_t *this,          int                             i = 0;          getaclreply                     *getaclreply = NULL; +        if (!frame->local) { +                gf_log (GF_ACL, GF_LOG_ERROR, "Invalid argument," +                       " frame->local NULL"); +                return  EINVAL; +        }          cs = frame->local; -        if (cs) -                getaclreply = &cs->args.getaclreply; - +        getaclreply = &cs->args.getaclreply;          if (op_ret == -1) {                  stat = nfs3_errno_to_nfsstat3 (op_errno);                  goto err; @@ -291,9 +296,14 @@ acl3_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,          int                             ret = -1;          nfs_user_t                      nfu = {0, }; +        if (!frame->local) { +                gf_log (GF_ACL, GF_LOG_ERROR, "Invalid argument," +                       " frame->local NULL"); +                return EINVAL; +        } +          cs = frame->local; -        if (cs) -                getaclreply = &cs->args.getaclreply; +        getaclreply = &cs->args.getaclreply;          if (op_ret == -1) {                  stat = nfs3_errno_to_nfsstat3 (op_errno); @@ -428,7 +438,6 @@ acl3_setacl_resume (void *carg)          if (!carg)                  return ret; -          cs = (nfs3_call_state_t *)carg;          acl3_check_fh_resolve_status (cs, stat, acl3err);          nfs_request_user_init (&nfu, cs->req); @@ -470,12 +479,22 @@ acl3svc_setacl (rpcsvc_request_t *req)          struct nfs3_fh                  fh;          struct nfs3_fh                 *fhp = NULL;          setaclargs                      setaclargs; -        aclentry                        aclentry[NFS_ACL_MAX_ENTRIES]; -        struct aclentry                 daclentry[NFS_ACL_MAX_ENTRIES]; +        aclentry                        *aclentry = NULL; +        struct aclentry                 *daclentry = NULL;          int                             *p = NULL, i = 0;          if (!req)                  return ret; +        aclentry =  GF_CALLOC (NFS_ACL_MAX_ENTRIES, sizeof(*aclentry), +                               gf_nfs_mt_arr); +        if (!aclentry) { +                goto rpcerr; +        } +        daclentry = GF_CALLOC (NFS_ACL_MAX_ENTRIES, sizeof(*daclentry), +                               gf_nfs_mt_arr); +        if (!daclentry) { +                goto rpcerr; +        }          acl3_validate_nfs3_state (req, nfs3, stat, rpcerr, ret);          nfs = nfs_state (nfs3->nfsx); @@ -532,19 +551,23 @@ acl3err:                  acl3svc_submit_reply (cs->req, (void *)&cs->args.setaclreply,                                        (acl3_serializer)xdr_serialize_setaclreply);                  nfs3_call_state_wipe (cs); +                GF_FREE(aclentry); +                GF_FREE(daclentry);                  return 0;          }  rpcerr:          if (ret < 0)                  nfs3_call_state_wipe (cs); - +        if (aclentry) +                GF_FREE (aclentry); +        if (daclentry) +                GF_FREE (daclentry);          return ret;  } -  rpcsvc_actor_t  acl3svc_actors[ACL3_PROC_COUNT] = {          {"NULL",       ACL3_NULL,      acl3svc_null,   NULL,   0},          {"GETACL",     ACL3_GETACL,    acl3svc_getacl, NULL,   0}, @@ -614,7 +637,7 @@ acl3svc_init(xlator_t *nfsx)                  goto err;          } -        rpcsvc_create_listeners (nfs->rpcsvc, options, "ACL"); +        ret = rpcsvc_create_listeners (nfs->rpcsvc, options, "ACL");          if (ret == -1) {                  gf_log (GF_ACL, GF_LOG_ERROR, "Unable to create listeners");                  dict_unref (options); diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index 286eab0b6d3..8639d7a7f4d 100644 --- a/xlators/nfs/server/src/mount3.c +++ b/xlators/nfs/server/src/mount3.c @@ -511,7 +511,8 @@ mnt3svc_update_mountlist (struct mount3_state *ms, rpcsvc_request_t *req,                  goto free_err;          } -        strcpy (me->exname, expname); +        strncpy (me->exname, expname, MNTPATHLEN); +          INIT_LIST_HEAD (&me->mlist);          /* Must get the IP or hostname of the client so we           * can map it into the mount entry. @@ -644,7 +645,7 @@ mnt3svc_lookup_mount_cbk (call_frame_t *frame, void  *cookie,          fh = nfs3_fh_build_uuid_root_fh (volumeid);  xmit_res: -        nfs3_fh_to_str (&fh, fhstr); +        nfs3_fh_to_str (&fh, fhstr, sizeof (fhstr));          gf_log (GF_MNT, GF_LOG_DEBUG, "MNT reply: fh %s, status: %d", fhstr,                  status);          if (op_ret == 0) { @@ -808,8 +809,8 @@ mnt3_resolve_state_wipe (mnt3_resolve_t *mres)  /* Sets up the component argument to contain the next component in the path and   * sets up path as an absolute path starting from the next component.   */ -char * -__setup_next_component (char *path, char *component) +static char * +setup_next_component (char *path, size_t plen, char *component, size_t clen)  {          char    *comp = NULL;          char    *nextcomp = NULL; @@ -817,7 +818,7 @@ __setup_next_component (char *path, char *component)          if ((!path) || (!component))                  return NULL; -        strcpy (component, path); +        strncpy (component, path, clen);          comp = index (component, (int)'/');          if (!comp)                  goto err; @@ -825,7 +826,7 @@ __setup_next_component (char *path, char *component)          comp++;          nextcomp = index (comp, (int)'/');          if (nextcomp) { -                strcpy (path, nextcomp); +                strncpy (path, nextcomp, plen);                  *nextcomp = '\0';          } else                  path[0] = '\0'; @@ -855,7 +856,9 @@ __mnt3_resolve_export_subdir_comp (mnt3_resolve_t *mres)          if (!mres)                  return ret; -        nextcomp = __setup_next_component (mres->remainingdir, dupsubdir); +        nextcomp = setup_next_component (mres->remainingdir, +                                         sizeof (mres->remainingdir), +                                         dupsubdir, sizeof (dupsubdir));          if (!nextcomp)                  goto err; @@ -972,7 +975,9 @@ __mnt3_resolve_subdir (mnt3_resolve_t *mres)          if (!mres)                  return ret; -        firstcomp = __setup_next_component (mres->remainingdir, dupsubdir); +        firstcomp = setup_next_component (mres->remainingdir, +                                          sizeof (mres->remainingdir), +                                          dupsubdir, sizeof (dupsubdir));          if (!firstcomp)                  goto err; @@ -1151,7 +1156,7 @@ mnt3_resolve_subdir (rpcsvc_request_t *req, struct mount3_state *ms,          mres->exp = exp;          mres->mstate = ms;          mres->req = req; -        strcpy (mres->remainingdir, subdir); +        strncpy (mres->remainingdir, subdir, MNTPATHLEN);          if (gf_nfs_dvm_off (nfs_state (ms->nfsx)))                  pfh = nfs3_fh_build_indexed_root_fh (mres->mstate->nfsx->children, mres->exp->vol);          else @@ -1475,6 +1480,8 @@ __build_mountlist (struct mount3_state *ms, int *count)                                  " failed");                          goto free_list;                  } +                if (!first) +                        first = mlist;                  mlist->ml_directory = GF_CALLOC (namelen + 2, sizeof (char),                                                   gf_nfs_mt_char); @@ -1505,9 +1512,6 @@ __build_mountlist (struct mount3_state *ms, int *count)                  } else                          prev = mlist; -                if (!first) -                        first = mlist; -                  (*count)++;          } @@ -1811,7 +1815,8 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, struct mount3_state *ms)                                  " failed");                          goto free_list;                  } - +                 if (!first) +                         first = elist;                  elist->ex_dir = GF_CALLOC (namelen + 2, sizeof (char),                                             gf_nfs_mt_char);                  if (!elist->ex_dir) { @@ -1819,16 +1824,10 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, struct mount3_state *ms)                                  " failed");                          goto free_list;                  } -                  strcpy (elist->ex_dir, ent->expname);                  addrstr = rpcsvc_volume_allowed (svc->options,                                                   ent->vol->name); -                if (addrstr) -                        addrstr = gf_strdup (addrstr); -                else -                        addrstr = gf_strdup ("No Access"); -                  elist->ex_groups = GF_CALLOC (1, sizeof (struct groupnode),                                                gf_nfs_mt_groupnode);                  if (!elist->ex_groups) { @@ -1836,16 +1835,23 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, struct mount3_state *ms)                                  " failed");                          goto free_list;                  } +                /*This check has to be done after checking +                 * elist->ex_groups allocation check to avoid resource leak; +                */ +                if (addrstr) +                        addrstr = gf_strdup (addrstr); +                else +                        addrstr = gf_strdup ("No Access"); +                if (!addrstr) { +                        goto free_list; +                }                  elist->ex_groups->gr_name = addrstr;                  if (prev) {                          prev->ex_next = elist;                          prev = elist;                  } else                          prev = elist; - -                if (!first) -                        first = elist;          }          ret = 0; @@ -1956,8 +1962,8 @@ mount3udp_add_mountlist (char *host, dirpath *expname)          while (*export == '/')                  export++; -        strcpy (me->exname, export); -        strcpy (me->hostname, host); +        strncpy (me->exname, export, MNTPATHLEN); +        strncpy (me->hostname, host, MNTPATHLEN);          INIT_LIST_HEAD (&me->mlist);          LOCK (&ms->mountlock);          { @@ -2363,8 +2369,11 @@ __mnt3_init_volume_export (struct mount3_state *ms, dict_t *opts)                  goto err;          } -        gf_string2boolean (optstr, &boolt); -        ret = 0; +        ret = gf_string2boolean (optstr, &boolt); +        if (ret < 0) { +                gf_log (GF_MNT, GF_LOG_ERROR, "Failed to convert" +                        " string to boolean"); +        }  err:          if (boolt == _gf_false) { @@ -2403,8 +2412,11 @@ __mnt3_init_dir_export (struct mount3_state *ms, dict_t *opts)                  goto err;          } -        gf_string2boolean (optstr, &boolt); -        ret = 0; +        ret = gf_string2boolean (optstr, &boolt); +        if (ret < 0) { +                gf_log (GF_MNT, GF_LOG_ERROR, "Failed to convert" +                        " string to boolean"); +         }  err:          if (boolt == _gf_false) { @@ -2581,7 +2593,7 @@ mnt3svc_init (xlator_t *nfsx)                  }          } -        rpcsvc_create_listeners (nfs->rpcsvc, options, nfsx->name); +        ret= rpcsvc_create_listeners (nfs->rpcsvc, options, nfsx->name);          if (ret == -1) {                  gf_log (GF_NFS, GF_LOG_ERROR, "Unable to create listeners");                  dict_unref (options); @@ -2669,7 +2681,7 @@ mnt1svc_init (xlator_t *nfsx)                  }          } -        rpcsvc_create_listeners (nfs->rpcsvc, options, nfsx->name); +        ret = rpcsvc_create_listeners (nfs->rpcsvc, options, nfsx->name);          if (ret == -1) {                  gf_log (GF_NFS, GF_LOG_ERROR, "Unable to create listeners");                  dict_unref (options); diff --git a/xlators/nfs/server/src/nfs-common.c b/xlators/nfs/server/src/nfs-common.c index b3853ded5fa..17126b8889e 100644 --- a/xlators/nfs/server/src/nfs-common.c +++ b/xlators/nfs/server/src/nfs-common.c @@ -94,7 +94,7 @@ nfs_mntpath_to_xlator (xlator_list_t *cl, char *path)          if ((!cl) || (!path))                  return NULL; -        strcpy (volname, path); +        strncpy (volname, path, MNTPATHLEN);          pathlen = strlen (volname);          gf_log (GF_NFS, GF_LOG_TRACE, "Subvolume search: %s", path);          if (volname[0] == '/') diff --git a/xlators/nfs/server/src/nfs-inodes.c b/xlators/nfs/server/src/nfs-inodes.c index 291152f857e..9e05ca2f5fe 100644 --- a/xlators/nfs/server/src/nfs-inodes.c +++ b/xlators/nfs/server/src/nfs-inodes.c @@ -57,10 +57,10 @@ nfl_inodes_init (struct nfs_fop_local *nfl, inode_t *inode, inode_t *parent,                  nfl->newparent = inode_ref (newparent);          if (name) -                strcpy (nfl->path, name); +                strncpy (nfl->path, name, NFS_NAME_MAX);          if (newname) -                strcpy (nfl->newpath, newname); +                strncpy (nfl->newpath, newname, NFS_NAME_MAX);          return;  } diff --git a/xlators/nfs/server/src/nfs-mem-types.h b/xlators/nfs/server/src/nfs-mem-types.h index 072512a52b0..ec6aec74b00 100644 --- a/xlators/nfs/server/src/nfs-mem-types.h +++ b/xlators/nfs/server/src/nfs-mem-types.h @@ -55,6 +55,7 @@ enum gf_nfs_mem_types_ {          gf_nfs_mt_aux_gids,          gf_nfs_mt_inode_ctx,          gf_nfs_mt_auth_spec, +        gf_nfs_mt_arr,          gf_nfs_mt_end  };  #endif diff --git a/xlators/nfs/server/src/nfs3-fh.c b/xlators/nfs/server/src/nfs3-fh.c index c4f59a622c4..3ca61056baa 100644 --- a/xlators/nfs/server/src/nfs3-fh.c +++ b/xlators/nfs/server/src/nfs3-fh.c @@ -120,17 +120,17 @@ nfs3_fh_is_root_fh (struct nfs3_fh *fh)  void -nfs3_fh_to_str (struct nfs3_fh *fh, char *str) +nfs3_fh_to_str (struct nfs3_fh *fh, char *str, size_t len)  { -        char            gfid[512]; -        char            exportid[512]; +        char            gfid[GF_UUID_BUF_SIZE]; +        char            exportid[GF_UUID_BUF_SIZE];          if ((!fh) || (!str))                  return; -        sprintf (str, "FH: exportid %s, gfid %s", -                 uuid_utoa_r (fh->exportid, exportid), -                 uuid_utoa_r (fh->gfid, gfid)); +        snprintf (str, len, "FH: exportid %s, gfid %s", +                  uuid_utoa_r (fh->exportid, exportid), +                  uuid_utoa_r (fh->gfid, gfid));  }  void diff --git a/xlators/nfs/server/src/nfs3-fh.h b/xlators/nfs/server/src/nfs3-fh.h index c22f913a3a5..03a58d93b96 100644 --- a/xlators/nfs/server/src/nfs3-fh.h +++ b/xlators/nfs/server/src/nfs3-fh.h @@ -97,7 +97,7 @@ extern void  nfs3_log_fh (struct nfs3_fh *fh);  extern void -nfs3_fh_to_str (struct nfs3_fh *fh, char *str); +nfs3_fh_to_str (struct nfs3_fh *fh, char *str, size_t len);  extern int  nfs3_fh_build_parent_fh (struct nfs3_fh *child, struct iatt *newstat, diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c index f7b1bb0cd65..4a5854d2b95 100644 --- a/xlators/nfs/server/src/nfs3-helpers.c +++ b/xlators/nfs/server/src/nfs3-helpers.c @@ -1607,13 +1607,14 @@ err:  void  nfs3_stat_to_errstr (uint32_t xid, char *op, nfsstat3 stat, int pstat, -                     char *errstr) +                     char *errstr, size_t len)  {          if ((!op) || (!errstr))                  return; -        sprintf (errstr, "XID: %x, %s: NFS: %d(%s), POSIX: %d(%s)", xid, op, -                 stat, nfsstat3_strerror (stat), pstat, strerror (pstat)); +        snprintf (errstr, len, "XID: %x, %s: NFS: %d(%s), POSIX: %d(%s)", +                  xid, op,stat, nfsstat3_strerror (stat), pstat, +                  strerror (pstat));  }  void @@ -1621,10 +1622,10 @@ nfs3_log_common_call (uint32_t xid, char *op, struct nfs3_fh *fh)  {          char    fhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; -        nfs3_fh_to_str (fh, fhstr); +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s", xid, op,                  fhstr);  } @@ -1636,9 +1637,9 @@ nfs3_log_fh_entry_call (uint32_t xid, char *op, struct nfs3_fh *fh,  {          char    fhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, fhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, name: %s", xid,                  op, fhstr, name);  } @@ -1651,10 +1652,10 @@ nfs3_log_rename_call (uint32_t xid, struct nfs3_fh *src, char *sname,          char    sfhstr[1024];          char    dfhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (src, sfhstr); -        nfs3_fh_to_str (dst, dfhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (src, sfhstr, sizeof (sfhstr)); +        nfs3_fh_to_str (dst, dfhstr, sizeof (dfhstr));          gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, RENAME: args: Src: %s, "                  "name: %s, Dst: %s, name: %s", xid, sfhstr, sname, dfhstr,                  dname); @@ -1672,9 +1673,9 @@ nfs3_log_create_call (uint32_t xid, struct nfs3_fh *fh, char *name,          char    unchkd[] = "UNCHECKED";          char    guarded[] = "GUARDED"; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, fhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          if (mode == EXCLUSIVE)                  modestr = exclmode;          else if (mode == GUARDED) @@ -1697,9 +1698,9 @@ nfs3_log_mknod_call (uint32_t xid, struct nfs3_fh *fh, char *name, int type)          char    sock[] = "SOCK";          char    fifo[] = "FIFO"; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, fhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          if (type == NF3CHR)                  modestr = chr;          else if (type == NF3BLK) @@ -1720,9 +1721,9 @@ nfs3_log_symlink_call (uint32_t xid, struct nfs3_fh *fh, char *name, char *tgt)  {          char    fhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, fhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, SYMLINK: args: %s, name: %s,"                  " target: %s", xid, fhstr, name, tgt);  } @@ -1735,10 +1736,10 @@ nfs3_log_link_call (uint32_t xid, struct nfs3_fh *fh, char *name,          char    dfhstr[1024];          char    tfhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, dfhstr); -        nfs3_fh_to_str (tgt, tfhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, dfhstr, sizeof (dfhstr)); +        nfs3_fh_to_str (tgt, tfhstr, sizeof (tfhstr));          gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, LINK: args: %s, name: %s,"                  " target: %s", xid, dfhstr, name, tfhstr);  } @@ -1750,9 +1751,9 @@ nfs3_log_rw_call (uint32_t xid, char *op, struct nfs3_fh *fh, offset3 offt,  {          char    fhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; -        nfs3_fh_to_str (fh, fhstr); +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          if (stablewrite == -1)                  gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, %s: args: %s, offset:"                          " %"PRIu64",  count: %"PRIu32, xid, op, fhstr, offt, @@ -3383,11 +3384,11 @@ void  nfs3_log_common_res (uint32_t xid, int op, nfsstat3 stat, int pstat)  {          char    errstr[1024]; -	int	ll = nfs3_loglevel (op, stat); +        int     ll = nfs3_loglevel (op, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s", errstr);  } @@ -3395,14 +3396,14 @@ void  nfs3_log_readlink_res (uint32_t xid, nfsstat3 stat, int pstat, char *linkpath)  {          char    errstr[1024]; -	int	ll = nfs3_loglevel (NFS3_READLINK, stat); +        int     ll = nfs3_loglevel (NFS3_READLINK, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; +        if (THIS->ctx->log.loglevel < ll) +                return; -        nfs3_stat_to_errstr (xid, "READLINK", stat, pstat, errstr); +        nfs3_stat_to_errstr (xid, "READLINK", stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s, target: %s", -		errstr, linkpath); +                errstr, linkpath);  } @@ -3411,12 +3412,12 @@ nfs3_log_read_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count,                     int is_eof, struct iovec *vec, int32_t veccount)  {          char    errstr[1024]; -	int	ll = GF_LOG_DEBUG; +        int     ll = GF_LOG_DEBUG;  	ll = nfs3_loglevel (NFS3_READ, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, "READ", stat, pstat, errstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, "READ", stat, pstat, errstr, sizeof (errstr));          if (vec)                  gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", is_eof:"                          " %d, vector: count: %d, len: %zd", errstr, count, @@ -3432,12 +3433,12 @@ nfs3_log_write_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count,                      int stable, uint64_t wverf)  {          char    errstr[1024]; -	int	ll = nfs3_loglevel (NFS3_WRITE, stat); +        int     ll = nfs3_loglevel (NFS3_WRITE, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; +        if (THIS->ctx->log.loglevel < ll) +                 return; -        nfs3_stat_to_errstr (xid, "WRITE", stat, pstat, errstr); +        nfs3_stat_to_errstr (xid, "WRITE", stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", %s,wverf: %"PRIu64                  , errstr, count, (stable == UNSTABLE)?"UNSTABLE":"STABLE",                  wverf); @@ -3450,12 +3451,12 @@ nfs3_log_newfh_res (uint32_t xid, int op, nfsstat3 stat, int pstat,  {          char    errstr[1024];          char    fhstr[1024]; -	int	ll = nfs3_loglevel (op, stat); +        int     ll = nfs3_loglevel (op, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr); -        nfs3_fh_to_str (newfh, fhstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, nfs3op_strings[op].str, stat, pstat, errstr, sizeof (errstr)); +        nfs3_fh_to_str (newfh, fhstr, sizeof (fhstr));          gf_log (GF_NFS3, nfs3_loglevel (op, stat), "%s, %s", errstr, fhstr);  } @@ -3466,11 +3467,11 @@ nfs3_log_readdir_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,                        count3 count, int is_eof)  {          char    errstr[1024]; -	int	ll = nfs3_loglevel (NFS3_READDIR, stat); +        int     ll = nfs3_loglevel (NFS3_READDIR, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, "READDIR", stat, pstat, errstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, "READDIR", stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s, count: %"PRIu32", cverf: %"PRIu64                  ", is_eof: %d", errstr, count, cverf, is_eof);  } @@ -3483,9 +3484,9 @@ nfs3_log_readdirp_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,          char    errstr[1024];  	int	ll = nfs3_loglevel (NFS3_READDIRP, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, "READDIRPLUS", stat, pstat, errstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, "READDIRPLUS", stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s, dircount: %"PRIu32", maxcount: %"                  PRIu32", cverf: %"PRIu64", is_eof: %d", errstr, dircount,                  maxcount, cverf, is_eof); @@ -3498,9 +3499,9 @@ nfs3_log_commit_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t wverf)          char    errstr[1024];  	int	ll = nfs3_loglevel (NFS3_COMMIT, stat); -	if (THIS->ctx->log.loglevel < ll) -		return; -        nfs3_stat_to_errstr (xid, "COMMIT", stat, pstat, errstr); +        if (THIS->ctx->log.loglevel < ll) +                return; +        nfs3_stat_to_errstr (xid, "COMMIT", stat, pstat, errstr, sizeof (errstr));          gf_log (GF_NFS3, ll, "%s, wverf: %"PRIu64, errstr, wverf);  } @@ -3511,10 +3512,10 @@ nfs3_log_readdir_call (uint32_t xid, struct nfs3_fh *fh, count3 dircount,  {          char    fhstr[1024]; -	if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) -		return; +        if (THIS->ctx->log.loglevel < GF_LOG_DEBUG) +                return; -        nfs3_fh_to_str (fh, fhstr); +        nfs3_fh_to_str (fh, fhstr, sizeof (fhstr));          if (maxcount == 0)                  gf_log (GF_NFS3, GF_LOG_DEBUG, "XID: %x, READDIR: args: %s," diff --git a/xlators/nfs/server/src/nfs3.c b/xlators/nfs/server/src/nfs3.c index 4e641228724..a52f47e6afa 100644 --- a/xlators/nfs/server/src/nfs3.c +++ b/xlators/nfs/server/src/nfs3.c @@ -265,8 +265,10 @@ out:                          xlatorp = nfs3_fh_to_xlator (cst->nfs3state,    \                                                       &cst->resolvefh);  \                          uuid_unparse (cst->resolvefh.gfid, gfid);       \ -                        sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\ -                        xlatorp ? xlatorp->name : "ERR", gfid);         \ +                        snprintf (buf, sizeof (buf), "(%s) %s : %s",             \ +                                  trans->peerinfo.identifier,           \ +                                  xlatorp ? xlatorp->name : "ERR",      \ +                                  gfid );                                \                          gf_log (GF_NFS3, GF_LOG_ERROR, "%s: %s",        \                                  strerror(cst->resolve_errno), buf);     \                          nfstat = nfs3_errno_to_nfsstat3 (cst->resolve_errno);\ @@ -285,8 +287,10 @@ out:                          xlatorp = nfs3_fh_to_xlator (cst->nfs3state,    \                                                       &cst->resolvefh);  \                          uuid_unparse (cst->resolvefh.gfid, gfid);       \ -                        sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\ -                        xlatorp ? xlatorp->name : "ERR", gfid);         \ +                        snprintf (buf, sizeof (buf), "(%s) %s : %s",             \ +                                  trans->peerinfo.identifier,     \ +                                  xlatorp ? xlatorp->name : "ERR",      \ +                                  gfid);         \                          gf_log (GF_NFS3, GF_LOG_ERROR, "%s: %s",        \                                  strerror(cst->resolve_errno), buf);     \                          nfstat = nfs3_errno_to_nfsstat3 (cs->resolve_errno);\ @@ -1313,7 +1317,11 @@ nfs3_lookup_parentdir_resume (void *carg)          nfs3_call_state_t               *cs = NULL;          inode_t                         *parent = NULL; -        GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err); +        if (!carg) { +                gf_log (GF_NFS3, GF_LOG_ERROR, "Invalid argument," +                        " carg value NULL"); +                return EINVAL; +        }          cs = (nfs3_call_state_t *)carg;          nfs3_check_fh_resolve_status (cs, stat, nfs3err); @@ -1384,7 +1392,11 @@ nfs3_lookup_resume (void *carg)          nfs3_call_state_t               *cs = NULL;          struct nfs3_fh                  newfh = {{0},}; -        GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err); +        if (!carg) { +                gf_log (GF_NFS3, GF_LOG_ERROR, "Invalid argument," +                        " carg value NULL"); +                return EINVAL; +        }          cs = (nfs3_call_state_t *)carg;          nfs3_check_fh_resolve_status (cs, stat, nfs3err); @@ -1539,7 +1551,11 @@ nfs3_access_resume (void *carg)          nfs_user_t              nfu = {0, };          nfs3_call_state_t       *cs = NULL; -        GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err); +        if (!carg) { +                gf_log (GF_NFS3, GF_LOG_ERROR, "Invalid argument," +                        " carg value NULL"); +                return EINVAL; +        }          cs = (nfs3_call_state_t *)carg;          nfs3_check_fh_resolve_status (cs, stat, nfs3err); @@ -2631,13 +2647,7 @@ nfs3svc_create (rpcsvc_request_t *req)          }          cval = (uint64_t *)args.how.createhow3_u.verf; -        if (cval) -                cverf = *cval; -        else { -                gf_log(GF_NFS3, GF_LOG_ERROR, -                       "Error getting createverf3 from args"); -                goto rpcerr; -        } +        cverf = *cval;          ret = nfs3_create (req, &dirfh, name, args.how.mode,                             &args.how.createhow3_u.obj_attributes, cverf); @@ -4382,16 +4392,8 @@ nfs3svc_readdir (rpcsvc_request_t *req)                  rpcsvc_request_seterr (req, GARBAGE_ARGS);                  goto rpcerr;          } -          cval = (uint64_t *) ra.cookieverf; - -        if (cval) -                verf =  *cval; -        else { -                gf_log(GF_NFS3, GF_LOG_ERROR, -                       "Error getting cookieverf from readdir args"); -                goto rpcerr; -        } +        verf =  *cval;          ret = nfs3_readdir (req, &fh, ra.cookie, verf, ra.count, 0);          if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE)) { @@ -4422,16 +4424,8 @@ nfs3svc_readdirp (rpcsvc_request_t *req)                  rpcsvc_request_seterr (req, GARBAGE_ARGS);                  goto rpcerr;          } -          cval = (uint64_t *) ra.cookieverf; - -        if (cval) -                cverf = *cval; -        else { -                gf_log (GF_NFS3, GF_LOG_ERROR, -                        "Error getting cookieverf from readdirp args"); -                goto rpcerr; -	} +        cverf = *cval;          ret = nfs3_readdir (req, &fh, ra.cookie, cverf, ra.dircount,                              ra.maxcount); @@ -5520,7 +5514,7 @@ nfs3_init_state (xlator_t *nfsx)          LOCK_INIT (&nfs3->fdlrulock);          nfs3->fdcount = 0; -        rpcsvc_create_listeners (nfs->rpcsvc, nfsx->options, nfsx->name); +        ret = rpcsvc_create_listeners (nfs->rpcsvc, nfsx->options, nfsx->name);          if (ret == -1) {                  gf_log (GF_NFS, GF_LOG_ERROR, "Unable to create listeners");                  goto free_localpool; diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c index ea8ca05ec29..b55c60e71fa 100644 --- a/xlators/nfs/server/src/nlm4.c +++ b/xlators/nfs/server/src/nlm4.c @@ -149,8 +149,10 @@ nfs3_fh_to_xlator (struct nfs3_state *nfs3, struct nfs3_fh *fh);                          xlatorp = nfs3_fh_to_xlator (cst->nfs3state,    \                                                       &cst->resolvefh);  \                          uuid_unparse (cst->resolvefh.gfid, gfid);       \ -                        sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\ -                        xlatorp ? xlatorp->name : "ERR", gfid);         \ +                        snprintf (buf, sizeof (buf), "(%s) %s : %s",             \ +                                  trans->peerinfo.identifier,           \ +                                  xlatorp ? xlatorp->name : "ERR",      \ +                                  gfid);                                \                          gf_log (GF_NLM, GF_LOG_ERROR, "Unable to resolve FH"\                                  ": %s", buf);                           \                          nfstat = nlm4_errno_to_nlm4stat (cst->resolve_errno);\ @@ -235,7 +237,7 @@ nlm_is_oh_same_lkowner (gf_lkowner_t *a, netobj *b)                  !memcmp (a->data, b->n_bytes, a->len));  } -nfsstat3 +nlm4_stats  nlm4_errno_to_nlm4stat (int errnum)  {          nlm4_stats        stat = nlm4_denied; @@ -1814,7 +1816,7 @@ nlm4_add_share_to_inode (nlm_share_t *share)          inode = share->inode;          ret = inode_ctx_get (inode, this, &ctx); -        if (ret || !head) { +        if (ret == -1) {                  ictx = GF_CALLOC (1, sizeof (struct nfs_inode_ctx),                                    gf_nfs_mt_inode_ctx);                  if (!ictx ) { @@ -2397,7 +2399,7 @@ nlm4svc_init(xlator_t *nfsx)                  goto err;          } -        rpcsvc_create_listeners (nfs->rpcsvc, options, "NLM"); +        ret = rpcsvc_create_listeners (nfs->rpcsvc, options, "NLM");          if (ret == -1) {                  gf_log (GF_NLM, GF_LOG_ERROR, "Unable to create listeners");                  dict_unref (options); diff --git a/xlators/nfs/server/src/nlmcbk_svc.c b/xlators/nfs/server/src/nlmcbk_svc.c index 5401dc39b96..bdfeba91492 100644 --- a/xlators/nfs/server/src/nlmcbk_svc.c +++ b/xlators/nfs/server/src/nlmcbk_svc.c @@ -92,10 +92,14 @@ void *  nsm_thread (void *argv)  {  	register SVCXPRT *transp; +        int ret = 0; -	pmap_unset (NLMCBK_PROGRAM, NLMCBK_V1); - -	transp = svcudp_create(RPC_ANYSOCK); +        ret = pmap_unset (NLMCBK_PROGRAM, NLMCBK_V1); +        if (ret == 0) { +                gf_log (GF_NLM, GF_LOG_ERROR, "pmap_unset failed"); +                return NULL; +        } +        transp = svcudp_create(RPC_ANYSOCK);  	if (transp == NULL) {  		gf_log (GF_NLM, GF_LOG_ERROR, "cannot create udp service.");                  return NULL;  | 
