X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi.c;h=8d8143e0b3396d23dc6ca1f5813688d42cf2810b;hp=aea7389eaf1696504fd9e2b079b745332fdafee9;hb=acce09601585c6481012065020ef08f9bf871340;hpb=54183b0637493c995ed2cd5d4cb3cce80192e6cb diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index aea7389..8d8143e 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -71,9 +71,8 @@ #include #include #include -#include #include -#include +#include static unsigned llapi_dir_filetype_table[] = { [DT_UNKNOWN]= 0, @@ -226,47 +225,47 @@ int parse_size(char *optarg, unsigned long long *size, /* XXX: llapi_xxx() functions return negative values upon failure */ int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset, - int stripe_count, int stripe_pattern) -{ - int page_size, rc; - - /* 64 KB is the largest common page size I'm aware of (on ia64), but - * check the local page size just in case. */ - page_size = LOV_MIN_STRIPE_SIZE; - if (getpagesize() > page_size) { - page_size = getpagesize(); - llapi_err_noerrno(LLAPI_MSG_WARN, - "warning: your page size (%u) is " - "larger than expected (%u)", page_size, - LOV_MIN_STRIPE_SIZE); - } - if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) { - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %lu, " - "must be an even multiple of %d bytes", - stripe_size, page_size); - return rc; - } - if (stripe_offset < -1 || stripe_offset > MAX_OBD_DEVICES) { - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d", - stripe_offset); - return rc; - } - if (stripe_count < -1 || stripe_count > LOV_MAX_STRIPE_COUNT) { - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d", - stripe_count); - return rc; - } - if (stripe_size >= (1ULL << 32)){ - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, - "warning: stripe size larger than 4G " - "is not currently supported and would wrap"); - return rc; - } - return 0; + int stripe_count, int stripe_pattern) +{ + int page_size, rc; + + /* 64 KB is the largest common page size I'm aware of (on ia64), but + * check the local page size just in case. */ + page_size = LOV_MIN_STRIPE_SIZE; + if (getpagesize() > page_size) { + page_size = getpagesize(); + llapi_err_noerrno(LLAPI_MSG_WARN, + "warning: your page size (%u) is " + "larger than expected (%u)", page_size, + LOV_MIN_STRIPE_SIZE); + } + if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) { + rc = -EINVAL; + llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %lu, " + "must be an even multiple of %d bytes", + stripe_size, page_size); + return rc; + } + if (stripe_offset < -1 || stripe_offset > MAX_OBD_DEVICES) { + rc = -EINVAL; + llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d", + stripe_offset); + return rc; + } + if (stripe_count < -1 || stripe_count > LOV_MAX_STRIPE_COUNT) { + rc = -EINVAL; + llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d", + stripe_count); + return rc; + } + if (stripe_size >= (1ULL << 32)) { + rc = -EINVAL; + llapi_error(LLAPI_MSG_ERROR, rc, + "warning: stripe size 4G or larger " + "is not currently supported and would wrap"); + return rc; + } + return 0; } /* return the first file matching this pattern */ @@ -410,6 +409,8 @@ static int get_param_obdvar(const char *fsname, const char *file_path, llapi_error(LLAPI_MSG_ERROR, rc, "'%s' is not on a Lustre filesystem", file_path); + if (fp != NULL) + fclose(fp); return rc; } } else if (fsname) { @@ -1016,7 +1017,7 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size, rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "Error reading pool list for '%s'", name); - return rc; + goto out; } else if ((rc == 0) && (cookie == NULL)) { /* end of directory */ break; @@ -1027,13 +1028,17 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size, continue; /* check output bounds */ - if (nb_entries >= list_size) - return -EOVERFLOW; + if (nb_entries >= list_size) { + rc = -EOVERFLOW; + goto out; + } /* +2 for '.' and final '\0' */ - if (used + strlen(pool.d_name) + strlen(fsname) + 2 - > buffer_size) - return -EOVERFLOW; + if (used + strlen(pool.d_name) + strlen(fsname) + 2 + > buffer_size) { + rc = -EOVERFLOW; + goto out; + } sprintf(buffer + used, "%s.%s", fsname, pool.d_name); poollist[nb_entries] = buffer + used; @@ -1041,8 +1046,9 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size, nb_entries++; } +out: closedir(dir); - return nb_entries; + return ((rc != 0) ? rc : nb_entries); } /* wrapper for lfs.c and obd.c */ @@ -1606,8 +1612,10 @@ retry_get_uuids: if (ret == -EOVERFLOW) { uuids_temp = realloc(uuids, obdcount * sizeof(struct obd_uuid)); - if (uuids_temp != NULL) + if (uuids_temp != NULL) { + uuids = uuids_temp; goto retry_get_uuids; + } else ret = -ENOMEM; } @@ -2682,9 +2690,15 @@ static int cb_get_mdt_index(char *path, DIR *parent, DIR *d, void *data, return ret; } + /* The 'LASSERT(parent != NULL || d != NULL);' guarantees + * that either 'd' or 'parent' is not null. + * So in all cases llapi_file_fget_mdtidx() is called, + * thus initializing 'mdtidx'. */ if (param->quiet || !(param->verbose & VERBOSE_DETAIL)) + /* coverity[uninit_use_in_call] */ llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx); else + /* coverity[uninit_use_in_call] */ llapi_printf(LLAPI_MSG_NORMAL, "%s\nmdt_index:\t%d\n", path, mdtidx); @@ -2850,6 +2864,8 @@ int llapi_ping(char *obd_type, char *obd_name) return rc; } + /* The purpose is to send a byte as a ping, whatever this byte is. */ + /* coverity[uninit_use_in_call] */ rc = write(fd, buf, 1); if (rc < 0) rc = -errno; @@ -3068,7 +3084,7 @@ static int rmtacl_notify(int ops) { FILE *fp; struct mntent *mnt; - int found = 0, fd, rc; + int found = 0, fd = 0, rc = 0; fp = setmntent(MOUNTED, "r"); if (fp == NULL) { @@ -3083,7 +3099,7 @@ static int rmtacl_notify(int ops) if (!mnt) break; - if (!llapi_is_lustre_mnt(mnt)) + if (!llapi_is_lustre_mnt(mnt)) continue; fd = open(mnt->mnt_dir, O_RDONLY | O_DIRECTORY); @@ -3091,20 +3107,24 @@ static int rmtacl_notify(int ops) rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "Can't open '%s'\n", mnt->mnt_dir); - return rc; + goto out; } rc = ioctl(fd, LL_IOC_RMTACL, ops); if (rc < 0) { rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "ioctl %d\n", fd); - return rc; + goto out; } found++; } + +out: endmntent(fp); - return found; + if (fd >= 0) + close(fd); + return ((rc != 0) ? rc : found); } static char *next_token(char *p, int div)