* Use is subject to license terms.
*/
/*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
fd = open(proc_path, O_RDONLY);
if (fd == -1) {
- llapi_err(LLAPI_MSG_ERROR, "open('%s') failed: %s\n",
- proc_path);
+ llapi_error(LLAPI_MSG_ERROR, -errno, "open('%s') failed: %s\n",
+ proc_path);
return -2;
}
rc = read(fd, buf, len - 1);
if (rc < 0) {
- llapi_err(LLAPI_MSG_ERROR, "read('%s') failed: %s\n",proc_path);
+ llapi_error(LLAPI_MSG_ERROR, -errno,
+ "read('%s') failed: %s\n", proc_path);
rc = -3;
} else if (rc == 0) {
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "read('%s') zero bytes\n", proc_path);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "read('%s') zero bytes\n", proc_path);
rc = -4;
} else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
buf[rc - 1] = '\0'; /* Remove trailing newline */
fp = popen("\\ls -d /proc/fs/lustre/lov/*lov* | head -1", "r");
if (!fp) {
- llapi_err(LLAPI_MSG_ERROR,
- "open(lustre/lov/*lov*) failed: %s\n");
+ llapi_error(LLAPI_MSG_ERROR, -errno,
+ "open(lustre/lov/*lov*) failed: %s\n");
return 2;
}
if (fscanf(fp, "%s", lov_path) < 1) {
- llapi_err(LLAPI_MSG_ERROR,"read lustre/lov/*lov* failed: %s\n");
+ llapi_error(LLAPI_MSG_ERROR, -EINVAL,
+ "read lustre/lov/*lov* failed: %s\n");
pclose(fp);
return 3;
}
if (lum_file1->lmm_stripe_count != stripe_count ||
lum_file1->lmm_stripe_count < min_stripe_count) {
- llapi_err(LLAPI_MSG_ERROR, "file1 stripe count %d != dir %d\n",
- lum_file1->lmm_stripe_count, stripe_count);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "file1 stripe count %d != dir %d\n",
+ lum_file1->lmm_stripe_count, stripe_count);
return 7;
}
if (lum_file1->lmm_stripe_count < stripe_count)
- llapi_err(LLAPI_MSG_WARN, "warning: file1 used fewer stripes "
- "%d < dir %d (likely due to bug 4900)\n",
- lum_file1->lmm_stripe_count, stripe_count);
+ llapi_err_noerrno(LLAPI_MSG_WARN,
+ "warning: file1 used fewer stripes "
+ "%d < dir %d (likely due to bug 4900)\n",
+ lum_file1->lmm_stripe_count, stripe_count);
if (lum_dir != NULL)
stripe_size = (int)lum_dir->lmm_stripe_size;
}
if (lum_file1->lmm_stripe_size != stripe_size) {
- llapi_err(LLAPI_MSG_ERROR, "file1 stripe size %d != dir %d\n",
- lum_file1->lmm_stripe_size, stripe_size);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "file1 stripe size %d != dir %d\n",
+ lum_file1->lmm_stripe_size, stripe_size);
return 8;
}
for (i = 0; i < stripe_count; i++)
if (lum_file1->lmm_objects[i].l_ost_idx !=
(stripe_offset + i) % ost_count) {
- llapi_err(LLAPI_MSG_WARN,
+ llapi_err_noerrno(LLAPI_MSG_WARN,
"warning: file1 non-sequential "
"stripe[%d] %d != %d\n", i,
lum_file1->lmm_objects[i].l_ost_idx,
ost_count;
idx = lum_file2->lmm_objects[0].l_ost_idx;
if (idx != next) {
- llapi_err(LLAPI_MSG_WARN, "warning: non-sequential "
+ llapi_err_noerrno(LLAPI_MSG_WARN,
+ "warning: non-sequential "
"file1 stripe[%d] %d != file2 stripe[0] %d\n",
stripe,
lum_file1->lmm_objects[stripe].l_ost_idx,
int lum_size;
if (argc < 3) {
- llapi_err(LLAPI_MSG_ERROR,
- "Usage: %s <dirname> <filename1> [filename2]\n",
- argv[0]);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "Usage: %s <dirname> <filename1> [filename2]\n",
+ argv[0]);
return 1;
}
dir = opendir(argv[1]);
if (dir == NULL) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s opendir failed\n", argv[1]);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: %s opendir failed\n", argv[1]);
return rc;
}
lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC);
if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
- rc = ENOMEM;
- llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d bytes "
- "for dir EA", lum_size);
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d bytes "
+ "for dir EA", lum_size);
goto cleanup;
}
rc = llapi_file_get_stripe(argv[1], lum_dir);
if (rc) {
- if (errno == ENODATA) {
+ if (rc == -ENODATA) {
free(lum_dir);
lum_dir = NULL;
} else {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR,
- "error: can't get EA for %s\n", argv[1]);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get EA for %s\n", argv[1]);
goto cleanup;
}
}
/* XXX should be llapi_lov_getname() */
rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
if (rc) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name for %s\n",
- argv[1]);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get lov name for %s\n",
+ argv[1]);
return rc;
}
if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
- rc = ENOMEM;
- llapi_err(LLAPI_MSG_ERROR,
- "error: can't allocate %d bytes for EA\n", lum_size);
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d bytes for EA\n",
+ lum_size);
goto cleanup;
}
rc = llapi_file_get_stripe(argv[2], lum_file1);
if (rc) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR,
- "error: unable to get EA for %s\n", argv[2]);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: unable to get EA for %s\n", argv[2]);
goto cleanup;
}
if (argc == 4) {
lum_file2 = (struct lov_user_md *)malloc(lum_size);
if (lum_file2 == NULL) {
- rc = ENOMEM;
- llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d "
- "bytes for file2 EA\n", lum_size);
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d "
+ "bytes for file2 EA\n", lum_size);
goto cleanup;
}
rc = llapi_file_get_stripe(argv[3], lum_file2);
if (rc) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR,
- "error: can't get EA for %s\n", argv[3]);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get EA for %s\n", argv[3]);
goto cleanup;
}
}
* Use is subject to license terms.
*/
/*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
llapi_msg_level = level;
}
-void llapi_err(int level, char *fmt, ...)
+/* llapi_error will preserve errno */
+void llapi_error(int level, int _rc, char *fmt, ...)
{
va_list args;
- int tmp_errno = abs(errno);
+ int tmp_errno = errno;
+ /* to protect using errno as _rc argument */
+ int rc = abs(_rc);
if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
return;
if (level & LLAPI_MSG_NO_ERRNO)
fprintf(stderr, "\n");
else
- fprintf(stderr, ": %s (%d)\n", strerror(tmp_errno), tmp_errno);
+ fprintf(stderr, ": %s (%d)\n", strerror(rc), rc);
+ errno = tmp_errno;
}
-#define llapi_err_noerrno(level, fmt, a...) \
- llapi_err((level) | LLAPI_MSG_NO_ERRNO, fmt, ## a)
-
+/* llapi_printf will preserve errno */
void llapi_printf(int level, char *fmt, ...)
{
va_list args;
+ int tmp_errno = errno;
if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
return;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
+ errno = tmp_errno;
}
/* size_units is unchanged if no specifier used */
int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
int stripe_count, int stripe_pattern)
{
- int page_size;
+ 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. */
LOV_MIN_STRIPE_SIZE);
}
if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) {
- errno = -EINVAL;
- llapi_err(LLAPI_MSG_ERROR, "error: bad stripe_size %lu, "
- "must be an even multiple of %d bytes",
- stripe_size, page_size);
- return errno;
+ 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) {
- errno = -EINVAL;
- llapi_err(LLAPI_MSG_ERROR, "error: bad stripe offset %d",
- stripe_offset);
- return errno;
+ 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) {
- errno = -EINVAL;
- llapi_err(LLAPI_MSG_ERROR, "error: bad stripe count %d",
- stripe_count);
- return errno;
+ rc = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
+ stripe_count);
+ return rc;
}
if (stripe_size >= (1ULL << 32)) {
- errno = -EINVAL;
- llapi_err(LLAPI_MSG_ERROR, "warning: stripe size larger than 4G"
- " is not currently supported and would wrap");
- return errno;
+ 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;
}
return rc;
if ((fd = fopen(buffer, "r")) == NULL)
- return -EINVAL;
+ return -errno;
while (fgets(buffer, sizeof(buffer), fd) != NULL) {
if (poolname == NULL) {
if (pool_name != NULL) {
char fsname[MAX_OBD_NAME + 1], *ptr;
- if (llapi_search_fsname(name, fsname)) {
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "'%s' is not on a Lustre filesystem", name);
- return -EINVAL;
+ rc = llapi_search_fsname(name, fsname);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "'%s' is not on a Lustre filesystem",
+ name);
+ return rc;
}
/* in case user gives the full pool name <fsname>.<poolname>,
*ptr = '\0';
if (strcmp(pool_name, fsname) != 0) {
*ptr = '.';
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "Pool '%s' is not on filesystem '%s'",
- pool_name, fsname);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "Pool '%s' is not on filesystem '%s'",
+ pool_name, fsname);
return -EINVAL;
}
pool_name = ptr + 1;
}
/* Make sure the pool exists and is non-empty */
- if ((rc = llapi_search_ost(fsname, pool_name, NULL)) < 1) {
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "pool '%s.%s' %s", fsname, pool_name,
- rc == 0 ? "has no OSTs" : "does not exist");
+ rc = llapi_search_ost(fsname, pool_name, NULL);
+ if (rc < 1) {
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "pool '%s.%s' %s", fsname, pool_name,
+ rc == 0 ? "has no OSTs" :
+ "does not exist");
return -EINVAL;
}
}
if (fd < 0) {
rc = -errno;
- llapi_err(LLAPI_MSG_ERROR, "unable to open '%s'", name);
+ llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
return rc;
}
- if ((rc = llapi_stripe_limit_check(stripe_size, stripe_offset,
- stripe_count, stripe_pattern)) != 0){
- errno = rc;
+ rc = llapi_stripe_limit_check(stripe_size, stripe_offset, stripe_count,
+ stripe_pattern);
+ if (rc != 0)
goto out;
- }
/* Initialize IOCTL striping pattern structure */
lum.lmm_magic = LOV_USER_MAGIC_V3;
/* get the mount point */
fp = setmntent(MOUNTED, "r");
if (fp == NULL) {
- llapi_err(LLAPI_MSG_ERROR,
- "setmntent(%s) failed: %s:", MOUNTED,
- strerror (errno));
- return -EIO;
+ rc = -EIO;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "setmntent(%s) failed", MOUNTED);
+ return rc;
}
while (1) {
if (getmntent_r(fp, &mnt, buf, sizeof(buf)) == NULL)
if (want & WANT_FD) {
fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
if (fd < 0) {
- perror("open");
rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error opening '%s'\n", mntdir);
} else {
*outfd = fd;
}
}
} else if (want & WANT_ERROR)
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "can't find fs root for '%s': %d",
- (want & WANT_PATH) ? fsname : path, rc);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "can't find fs root for '%s': %d",
+ (want & WANT_PATH) ? fsname : path, rc);
return rc;
}
*ptr = '\0';
path = realpath(buf, NULL);
if (path == NULL) {
- llapi_err(LLAPI_MSG_ERROR,
- "pathname '%s' cannot expand",
- pathname);
- return -errno;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "pathname '%s' cannot expand",
+ pathname);
+ return rc;
}
}
}
rc = poolpath(fsname, NULL, pathname);
if (rc != 0) {
- errno = -rc;
- llapi_err(LLAPI_MSG_ERROR, "Lustre filesystem '%s' not found",
- fsname);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Lustre filesystem '%s' not found",
+ fsname);
return rc;
}
llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
sprintf(path, "%s/%s", pathname, pool);
if ((fd = fopen(path, "r")) == NULL) {
- llapi_err(LLAPI_MSG_ERROR, "Cannot open %s", path);
- return -EINVAL;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "Cannot open %s", path);
+ return rc;
}
rc = 0;
/* only absolute pathname is supported */
if (*name != '/')
return -EINVAL;
+
if (!realpath(name, rname)) {
rc = -errno;
- llapi_err(LLAPI_MSG_ERROR, "invalid path '%s'", name);
+ llapi_error(LLAPI_MSG_ERROR, rc, "invalid path '%s'",
+ name);
return rc;
}
rc = poolpath(NULL, rname, pathname);
if (rc != 0) {
- errno = -rc;
- llapi_err(LLAPI_MSG_ERROR, "'%s' is not"
- " a Lustre filesystem", name);
+ llapi_error(LLAPI_MSG_ERROR, rc, "'%s' is not"
+ " a Lustre filesystem", name);
return rc;
}
strcpy(fsname, rname);
rc = poolpath(fsname, NULL, pathname);
}
if (rc != 0) {
- errno = -rc;
- llapi_err(LLAPI_MSG_ERROR, "Lustre filesystem '%s' not found",
- name);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Lustre filesystem '%s' not found", name);
return rc;
}
llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
if ((dir = opendir(pathname)) == NULL) {
- llapi_err(LLAPI_MSG_ERROR, "Could not open pool list for '%s'",
- name);
- return -errno;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Could not open pool list for '%s'",
+ name);
+ return rc;
}
while(1) {
rc = readdir_r(dir, &pool, &cookie);
if (rc != 0) {
- llapi_err(LLAPI_MSG_ERROR,
- "Error reading pool list for '%s'", name);
- return -errno;
- } else if ((rc == 0) && (cookie == NULL))
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Error reading pool list for '%s'", name);
+ return rc;
+ } else if ((rc == 0) && (cookie == NULL)) {
/* end of directory */
break;
+ }
/* ignore . and .. */
if (!strcmp(pool.d_name, ".") || !strcmp(pool.d_name, ".."))
static int common_param_init(struct find_param *param)
{
param->lumlen = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC_V3);
- if ((param->lmd = malloc(sizeof(lstat_t) + param->lumlen)) == NULL) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: allocation of %d bytes for ioctl",
- sizeof(lstat_t) + param->lumlen);
+ param->lmd = malloc(sizeof(lstat_t) + param->lumlen);
+ if (param->lmd == NULL) {
+ llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
+ "error: allocation of %d bytes for ioctl",
+ sizeof(lstat_t) + param->lumlen);
return -ENOMEM;
}
return 0;
}
+/* set errno upon failure */
static DIR *opendir_parent(char *path)
{
DIR *parent;
* Do the regular lstat(2) instead. */
ret = lstat_f(path, st);
if (ret) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: lstat failed for %s",
- __func__, path);
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "error: %s: lstat failed for %s",
+ __func__, path);
return ret;
}
} else if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_WARN,
- "warning: %s: %s does not exist",
- __func__, path);
- return -ENOENT;
+ ret = -errno;
+ llapi_error(LLAPI_MSG_WARN, ret,
+ "warning: %s: %s does not exist",
+ __func__, path);
+ return ret;
} else {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: IOC_MDC_GETFILEINFO failed for %s",
- __func__, path);
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "error: %s: IOC_MDC_GETFILEINFO failed for %s",
+ __func__, path);
return ret;
}
}
d = opendir(path);
if (!d && errno != ENOTDIR) {
- llapi_err(LLAPI_MSG_ERROR, "%s: Failed to open '%s'",
- __func__, path);
- return -EINVAL;
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret, "%s: Failed to open '%s'",
+ __func__, path);
+ return ret;
} else if (!d && !parent) {
/* ENOTDIR. Open the parent dir. */
p = opendir_parent(path);
if (!p)
- GOTO(out, ret = -EINVAL);
+ GOTO(out, ret = -errno);
}
if (sem_init && (ret = sem_init(path, parent ?: p, d, data, de)))
path[len] = 0;
if ((len + dent->d_reclen + 2) > size) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: string buffer is too small",
- __func__);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "error: %s: string buffer is too small",
+ __func__);
break;
}
switch (dent->d_type) {
case DT_UNKNOWN:
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: '%s' is UNKNOWN type %d",
- __func__, dent->d_name, dent->d_type);
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "error: %s: '%s' is UNKNOWN type %d",
+ __func__, dent->d_name, dent->d_type);
break;
case DT_DIR:
ret = llapi_semantic_traverse(path, size, d, sem_init,
char *buf;
if (len > PATH_MAX) {
- llapi_err(LLAPI_MSG_ERROR, "Path name '%s' is too long", path);
- return -EINVAL;
+ ret = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "Path name '%s' is too long", path);
+ return ret;
}
buf = (char *)malloc(PATH_MAX + 1);
{
int rc = ioctl(fd, OBD_IOC_GETNAME, lov_name);
if (rc) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name.");
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get lov name.");
}
return rc;
}
fd = open(path, O_RDONLY);
if (fd < 0) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error opening %s", path);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
return rc;
}
rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
close(fd);
-
return rc;
}
lov_name.uuid);
fp = fopen(buf, "r");
if (fp == NULL) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error: opening '%s'", buf);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'", buf);
return rc;
}
return -EOVERFLOW;
*ost_count = index;
- return rc;
+ return 0;
}
/* Check if user specified value matches a real uuid. Ignore _UUID,
/* Get the lov name */
rc = llapi_file_fget_lov_uuid(dirfd(dir), &lov_uuid);
if (rc) {
- if (errno != ENOTTY) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR,
- "error: can't get lov name: %s", dname);
+ if (rc != -ENOTTY) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get lov name: %s", dname);
} else {
rc = 0;
}
lov_uuid.uuid);
fp = fopen(buf, "r");
if (fp == NULL) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error: opening '%s'", buf);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'", buf);
return rc;
}
ret = -ENOMEM;
}
- llapi_err(LLAPI_MSG_ERROR, "get ost uuid failed");
+ llapi_error(LLAPI_MSG_ERROR, ret, "get ost uuid failed");
return ret;
}
prefix);
sp = is_dir ? " " : "";
}
- if (is_dir)
+ if (is_dir)
llapi_printf(LLAPI_MSG_NORMAL, "%d%s",
lum->lmm_stripe_count ==
(typeof(lum->lmm_stripe_count))(-1) ? -1 :
sp, prefix);
sp = is_dir ? " " : "";
}
- if (is_dir)
+ if (is_dir)
llapi_printf(LLAPI_MSG_NORMAL, "%d%s",
lum->lmm_stripe_offset ==
(typeof(lum->lmm_stripe_offset))(-1) ? -1 :
}
if ((fd = open(dname, O_RDONLY)) == -1) {
- rc = errno;
+ rc = -errno;
free(dname);
return rc;
}
strcpy((char *)lum, fname);
if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
- rc = errno;
+ rc = -errno;
if (close(fd) == -1 && rc == 0)
- rc = errno;
+ rc = -errno;
free(dname);
-
return rc;
}
rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
- name, rc);
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
+ name, rc);
return rc;
}
- return ioctl(dirfd, IOC_MDC_LOOKUP, buf);
+ rc = ioctl(dirfd, IOC_MDC_LOOKUP, buf);
+ if (rc < 0)
+ rc = -errno;
+ return rc;
}
/* Check if the value matches 1 of the given criteria (e.g. --atime +/-N).
lustre_fs = 0;
ret = lstat_f(path, st);
if (ret) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: lstat failed for %s",
- __func__, path);
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "error: %s: lstat failed for %s",
+ __func__, path);
return ret;
}
} else if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_WARN,
+ llapi_error(LLAPI_MSG_WARN, -ENOENT,
"warning: %s: %s does not exist",
__func__, path);
goto decided;
} else {
- llapi_err(LLAPI_MSG_ERROR,"error: %s: %s failed for %s",
- __func__, dir ? "LL_IOC_MDC_GETINFO" :
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "error: %s: %s failed for %s",
+ __func__, dir ? "LL_IOC_MDC_GETINFO" :
"IOC_MDC_GETFILEINFO", path);
return ret;
}
if (ret) {
if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_ERROR,
- "warning: %s: %s does not exist",
- __func__, path);
+ llapi_error(LLAPI_MSG_ERROR, -ENOENT,
+ "warning: %s: %s does not exist",
+ __func__, path);
goto decided;
} else {
- llapi_err(LLAPI_MSG_ERROR,
- "%s: IOC_LOV_GETINFO on %s failed",
- __func__, path);
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "%s: IOC_LOV_GETINFO on %s failed",
+ __func__, path);
return ret;
}
}
}
if (ret) {
- if (errno == ENODATA) {
+ if (errno == ENODATA && d != NULL) {
+ /* We need to "fake" the "use the default" values
+ * since the lmm struct is zeroed out at this point.
+ * The magic needs to be set in order to satisfy
+ * a check later on in the code path.
+ * The object_seq needs to be set for the "(Default)"
+ * prefix to be displayed. */
+ struct lov_user_md *lmm = ¶m->lmd->lmd_lmm;
+ lmm->lmm_magic = LOV_MAGIC_V1;
+ lmm->lmm_object_gr = LOV_OBJECT_GROUP_DEFAULT;
+ lmm->lmm_stripe_count = 0;
+ lmm->lmm_stripe_size = 0;
+ lmm->lmm_stripe_offset = -1;
+ goto dump;
+
+ } else if (errno == ENODATA && parent != NULL) {
if (!param->obduuid)
llapi_printf(LLAPI_MSG_NORMAL,
"%s has no stripe info\n", path);
goto out;
- } else if (errno == ENOTTY) {
- llapi_err(LLAPI_MSG_ERROR,
- "%s: '%s' not on a Lustre fs?",
- __func__, path);
} else if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_WARN,
- "warning: %s: %s does not exist",
- __func__, path);
+ llapi_error(LLAPI_MSG_WARN, -ENOENT,
+ "warning: %s: %s does not exist",
+ __func__, path);
goto out;
+ } else if (errno == ENOTTY) {
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "%s: '%s' not on a Lustre fs?",
+ __func__, path);
} else {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: %s failed for %s",
- __func__, d ? "LL_IOC_LOV_GETSTRIPE" :
- "IOC_MDC_GETFILESTRIPE", path);
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "error: %s: %s failed for %s",
+ __func__, d ? "LL_IOC_LOV_GETSTRIPE" :
+ "IOC_MDC_GETFILESTRIPE", path);
}
return ret;
}
+dump:
llapi_lov_dump_user_lmm(param, path, d ? 1 : 0);
out:
/* Do not get down anymore? */
data.ioc_pbuf2 = (char *)uuid_buf;
data.ioc_plen2 = sizeof(struct obd_uuid);
- if ((rc = obd_ioctl_pack(&data, &rawbuf, sizeof(raw))) != 0) {
- llapi_err(LLAPI_MSG_ERROR,
- "llapi_obd_statfs: error packing ioctl data");
+ rc = obd_ioctl_pack(&data, &rawbuf, sizeof(raw));
+ if (rc != 0) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "llapi_obd_statfs: error packing ioctl data");
return rc;
}
if (fd < 0) {
rc = errno ? -errno : -EBADF;
- llapi_err(LLAPI_MSG_ERROR, "error: %s: opening '%s'",
- __func__, path);
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'",
+ __func__, path);
return rc;
}
rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
fd = open(path, O_WRONLY);
if (fd < 0) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error opening %s", path);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
return rc;
}
rc = write(fd, buf, 1);
+ if (rc < 0)
+ rc = -errno;
close(fd);
if (rc == 1)
return rc;
}
-int llapi_target_iterate(int type_num, char **obd_type,void *args,llapi_cb_t cb)
+int llapi_target_iterate(int type_num, char **obd_type,
+ void *args, llapi_cb_t cb)
{
char buf[MAX_STRING_SIZE];
FILE *fp = fopen(DEVICES_LIST, "r");
int i, rc = 0;
if (fp == NULL) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "error: opening "DEVICES_LIST);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: opening "DEVICES_LIST);
return rc;
}
}
}
fclose(fp);
- return rc;
+ return 0;
}
static void do_target_check(char *obd_type_name, char *obd_name,
if (rc == ENOTCONN) {
llapi_printf(LLAPI_MSG_NORMAL, "%s inactive.\n", obd_name);
} else if (rc) {
- llapi_err(LLAPI_MSG_ERROR, "error: check '%s'", obd_name);
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: check '%s'", obd_name);
} else {
llapi_printf(LLAPI_MSG_NORMAL, "%s active.\n", obd_name);
}
root = opendir(dir);
if (root == NULL) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "open %s failed", dir);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", dir);
return rc;
}
rc = ioctl(dirfd(root), OBD_IOC_LLOG_CATINFO, buf);
- if (rc)
- llapi_err(LLAPI_MSG_ERROR, "ioctl OBD_IOC_CATINFO failed");
- else
+ if (rc) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "ioctl OBD_IOC_CATINFO failed");
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%s", data.ioc_pbuf1);
+ }
closedir(root);
return rc;
root = opendir(mnt);
if (!root) {
- llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
- return -1;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
}
rc = ioctl(dirfd(root), LL_IOC_QUOTACHECK, check_type);
+ if (rc < 0)
+ rc = -errno;
closedir(root);
return rc;
root = opendir(mnt);
if (!root) {
- llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
- return -1;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
}
while (1) {
}
closedir(root);
- return rc;
+ return 0;
}
int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
root = opendir(mnt);
if (!root) {
- llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
- return -1;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
}
rc = ioctl(dirfd(root), LL_IOC_QUOTACTL, qctl);
+ if (rc < 0)
+ rc = -errno;
closedir(root);
return rc;
if (rc) {
if (errno == ENODATA) {
if (!param->obduuid && !param->quiet)
- llapi_err(LLAPI_MSG_ERROR,
- "%s has no stripe info", path);
+ llapi_error(LLAPI_MSG_ERROR, -ENODATA,
+ "%s has no stripe info", path);
rc = 0;
} else if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_ERROR,
- "warning: %s: %s does not exist",
- __func__, path);
+ llapi_error(LLAPI_MSG_ERROR, -ENOENT,
+ "warning: %s: %s does not exist",
+ __func__, path);
rc = 0;
} else if (errno != EISDIR) {
- rc = errno;
- llapi_err(LLAPI_MSG_ERROR, "%s ioctl failed for %s.",
- d ? "LL_IOC_MDC_GETINFO" :
- "IOC_MDC_GETFILEINFO", path);
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "%s ioctl failed for %s.",
+ d ? "LL_IOC_MDC_GETINFO" :
+ "IOC_MDC_GETFILEINFO", path);
}
return rc;
}
* invoke syscall directly. */
rc = syscall(SYS_chown, path, -1, -1);
if (rc)
- llapi_err(LLAPI_MSG_ERROR, "error: chown %s", path);
+ llapi_error(LLAPI_MSG_ERROR, errno,
+ "error: chown %s", path);
rc = chmod(path, st->st_mode);
- if (rc)
- llapi_err(LLAPI_MSG_ERROR, "error: chmod %s (%hu)",
- path, st->st_mode);
+ if (rc) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: chmod %s (%hu)",
+ path, st->st_mode);
+ }
return rc;
}
int llapi_quotachown(char *path, int flag)
{
struct find_param param;
-
+
memset(¶m, 0, sizeof(param));
param.recursive = 1;
param.verbose = 0;
return -errno;
rc = ioctl(fd, LL_IOC_PATH2FID, fid);
-
+ if (rc)
+ rc = -errno;
close(fd);
return rc;
}
root = opendir(mnt);
if (!root) {
- llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
- return -1;
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ return rc;
}
rc = ioctl(dirfd(root), LL_IOC_GET_CONNECT_FLAGS, flags);
+ if (rc < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "ioctl on %s for getting connect flags failed", mnt);
+ }
closedir(root);
- if (rc < 0)
- llapi_err(LLAPI_MSG_ERROR,
- "ioctl on %s for getting connect flags failed", mnt);
return rc;
}
rc = ioctl(fd, OBD_GET_VERSION, buffer);
if (rc == -1) {
- rc = errno;
+ rc = -errno;
close(fd);
- return -rc;
+ return rc;
}
close(fd);
*version = data->ioc_bulk;