summaryrefslogtreecommitdiffstats
path: root/xlators/nfs/server/src/mount3.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-04 09:51:26 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-04 04:58:14 +0000
commit81cbbfd1d870bea49b8aafe7bebb9e8251190918 (patch)
tree48e02860d8ddc43067ab1836adba90f8a03a14d7 /xlators/nfs/server/src/mount3.c
parent4cfbdfd0c851e4a5c6f4303a9141f34f8887b376 (diff)
Multiple files: calloc -> malloc
xlators/storage/posix/src/posix-inode-fd-ops.c: xlators/storage/posix/src/posix-helpers.c: xlators/storage/bd/src/bd.c: xlators/protocol/client/src/client-lk.c: xlators/performance/quick-read/src/quick-read.c: xlators/performance/io-cache/src/page.c xlators/nfs/server/src/nfs3-helpers.c xlators/nfs/server/src/nfs-fops.c xlators/nfs/server/src/mount3udp_svc.c xlators/nfs/server/src/mount3.c xlators/mount/fuse/src/fuse-helpers.c xlators/mount/fuse/src/fuse-bridge.c xlators/mgmt/glusterd/src/glusterd-utils.c xlators/mgmt/glusterd/src/glusterd-syncop.h xlators/mgmt/glusterd/src/glusterd-snapshot.c xlators/mgmt/glusterd/src/glusterd-rpc-ops.c xlators/mgmt/glusterd/src/glusterd-replace-brick.c xlators/mgmt/glusterd/src/glusterd-op-sm.c xlators/mgmt/glusterd/src/glusterd-mgmt.c xlators/meta/src/subvolumes-dir.c xlators/meta/src/graph-dir.c xlators/features/trash/src/trash.c xlators/features/shard/src/shard.h xlators/features/shard/src/shard.c xlators/features/marker/src/marker-quota.c xlators/features/locks/src/common.c xlators/features/leases/src/leases-internal.c xlators/features/gfid-access/src/gfid-access.c xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c xlators/features/bit-rot/src/bitd/bit-rot.c xlators/features/bit-rot/src/bitd/bit-rot-scrub.c bxlators/encryption/crypt/src/metadata.c xlators/encryption/crypt/src/crypt.c xlators/performance/md-cache/src/md-cache.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible It doesn't make sense to calloc (allocate and clear) memory when the code right away fills that memory with data. It may be optimized by the compiler, or have a microscopic performance improvement. In some cases, also changed allocation size to be sizeof some struct or type instead of a pointer - easier to read. In some cases, removed redundant strlen() calls by saving the result into a variable. 1. Only done for the straightforward cases. There's room for improvement. 2. Please review carefully, especially for string allocation, with the terminating NULL string. Only compile-tested! .. and allocate memory as much as needed. xlators/nfs/server/src/mount3.c : Don't blindly allocate PATH_MAX, but strlen() the string and allocate appropriately. Also, align error messges. updates: bz#1193929 Original-Author: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Ibda6f33dd180b7f7694f20a12af1e9576fe197f5
Diffstat (limited to 'xlators/nfs/server/src/mount3.c')
-rw-r--r--xlators/nfs/server/src/mount3.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c
index 187c975081d..f3d7def64d0 100644
--- a/xlators/nfs/server/src/mount3.c
+++ b/xlators/nfs/server/src/mount3.c
@@ -761,6 +761,7 @@ mnt3svc_lookup_mount_cbk (call_frame_t *frame, void *cookie,
char *path = NULL;
uuid_t mountid = {1, };
char fhstr[1536];
+ int alloclen = 0;
req = (rpcsvc_request_t *)frame->local;
@@ -786,14 +787,16 @@ mnt3svc_lookup_mount_cbk (call_frame_t *frame, void *cookie,
if (status != MNT3_OK)
goto xmit_res;
- path = GF_CALLOC (PATH_MAX, sizeof (char), gf_nfs_mt_char);
+ alloclen = strlen(mntxl->name) + 2;
+ path = GF_MALLOC (alloclen, gf_nfs_mt_char);
if (!path) {
- gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM, NFS_MSG_NO_MEMORY,
- "Out of memory");
+ gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
+ NFS_MSG_NO_MEMORY,
+ "Memory allocation failed.");
goto xmit_res;
}
- snprintf (path, PATH_MAX, "/%s", mntxl->name);
+ snprintf (path, alloclen, "/%s", mntxl->name);
mnt3svc_update_mountlist (ms, req, path, NULL);
GF_FREE (path);
if (gf_nfs_dvm_off (nfs_state (ms->nfsx))) {
@@ -1148,18 +1151,19 @@ mnt3_resolve_subdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
nfs3_fh_build_child_fh (&mres->parentfh, buf, &fh);
if (strlen (mres->remainingdir) <= 0) {
- size_t alloclen;
+ int alloclen;
op_ret = -1;
mntstat = MNT3_OK;
/* Construct the full path */
+ int resolveloc_path_len = strlen(mres->resolveloc.path);
alloclen = strlen (mres->exp->expname) +
- strlen (mres->resolveloc.path) + 1;
- mres->exp->fullpath = GF_CALLOC (alloclen, sizeof (char),
- gf_nfs_mt_char);
+ resolveloc_path_len + 1;
+ mres->exp->fullpath = GF_MALLOC (alloclen, gf_nfs_mt_char);
if (!mres->exp->fullpath) {
- gf_msg (GF_MNT, GF_LOG_CRITICAL, ENOMEM,
- NFS_MSG_NO_MEMORY, "Allocation failed.");
+ gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
+ NFS_MSG_NO_MEMORY,
+ "Memory allocation failed.");
goto err;
}
snprintf (mres->exp->fullpath, alloclen, "%s%s",
@@ -1178,7 +1182,9 @@ mnt3_resolve_subdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
goto err;
}
- path = GF_CALLOC (PATH_MAX, sizeof (char), gf_nfs_mt_char);
+ alloclen = strlen (mres->exp->vol->name) +
+ resolveloc_path_len + 2;
+ path = GF_MALLOC (alloclen, gf_nfs_mt_char);
if (!path) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
NFS_MSG_NO_MEMORY,
@@ -1190,7 +1196,7 @@ mnt3_resolve_subdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
*/
__mnt3_build_mountid_from_path (authorized_path, fh.mountid);
- snprintf (path, PATH_MAX, "/%s%s", mres->exp->vol->name,
+ snprintf (path, alloclen, "/%s%s", mres->exp->vol->name,
mres->resolveloc.path);
mnt3svc_update_mountlist (mres->mstate, mres->req,
@@ -1293,12 +1299,12 @@ mnt3_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
/* Building the actual mount path to be mounted */
path_len = strlen (mres->exp->vol->name) + strlen (absolute_path)
+ strlen (mres->remainingdir) + 1;
- real_loc = GF_CALLOC (1, path_len, gf_nfs_mt_char);
+ real_loc = GF_MALLOC (path_len, gf_nfs_mt_char);
if (!real_loc) {
ret = -ENOMEM;
goto mnterr;
}
- sprintf (real_loc , "%s%s", mres->exp->vol->name, absolute_path);
+ snprintf (real_loc, path_len, "%s%s", mres->exp->vol->name, absolute_path);
gf_path_strip_trailing_slashes (real_loc);
/* There may entries after symlink in the mount path,
@@ -2314,7 +2320,7 @@ __build_mountlist (struct mount3_state *ms, int *count)
if (!first)
first = mlist;
- mlist->ml_directory = GF_CALLOC (namelen + 2, sizeof (char),
+ mlist->ml_directory = GF_MALLOC (namelen + 2,
gf_nfs_mt_char);
if (!mlist->ml_directory) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
@@ -2325,7 +2331,7 @@ __build_mountlist (struct mount3_state *ms, int *count)
strcpy (mlist->ml_directory, me->exname);
namelen = strlen (me->hostname);
- mlist->ml_hostname = GF_CALLOC (namelen + 2, sizeof (char),
+ mlist->ml_hostname = GF_MALLOC (namelen + 2,
gf_nfs_mt_char);
if (!mlist->ml_hostname) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
@@ -2654,7 +2660,6 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, struct mount3_state *ms)
if (!nfs_subvolume_started (nfs, ent->vol))
continue;
- namelen = strlen (ent->expname) + 1;
elist = GF_CALLOC (1, sizeof (*elist), gf_nfs_mt_exportnode);
if (!elist) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
@@ -2663,7 +2668,8 @@ mnt3_xlchildren_to_exports (rpcsvc_t *svc, struct mount3_state *ms)
}
if (!first)
first = elist;
- elist->ex_dir = GF_CALLOC (namelen + 2, sizeof (char),
+ namelen = strlen (ent->expname);
+ elist->ex_dir = GF_MALLOC (namelen + 2,
gf_nfs_mt_char);
if (!elist->ex_dir) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM,
@@ -3324,7 +3330,7 @@ mnt3_init_export_ent (struct mount3_state *ms, xlator_t *xl, char *exportpath,
else
alloclen = strlen (xl->name) + 2;
- exp->expname = GF_CALLOC (alloclen, sizeof (char), gf_nfs_mt_char);
+ exp->expname = GF_MALLOC (alloclen, gf_nfs_mt_char);
if (!exp->expname) {
gf_msg (GF_MNT, GF_LOG_ERROR, ENOMEM, NFS_MSG_NO_MEMORY,
"Memory allocation failed");