When calling llapi_error() the format string should not end in a
newline, since the error string is appended to the output with
its own newline.
Fix several callers to not supply their own newline, and callers
that duplicate the error string in the error message itself.
In the case that there are callers that *do* include a newline,
handle this gracefully to avoid splitting the error across lines.
Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ie8f7206d82faccb3b33e2fc62b00f5226b3ebbe5
Reviewed-on: https://review.whamcloud.com/36176
Reviewed-by: Ben Evans <bevans@cray.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
static void error_callback_default(enum llapi_message_level level, int err,
const char *fmt, va_list ap)
{
static void error_callback_default(enum llapi_message_level level, int err,
const char *fmt, va_list ap)
{
+ bool has_nl = strchr(fmt, '\n') != NULL;
+
if (liblustreapi_cmd != NULL)
fprintf(stderr, "%s %s: ", program_invocation_short_name,
liblustreapi_cmd);
else
fprintf(stderr, "%s: ", program_invocation_short_name);
if (liblustreapi_cmd != NULL)
fprintf(stderr, "%s %s: ", program_invocation_short_name,
liblustreapi_cmd);
else
fprintf(stderr, "%s: ", program_invocation_short_name);
- vfprintf(stderr, fmt, ap);
- if (level & LLAPI_MSG_NO_ERRNO)
- fprintf(stderr, "\n");
- else
+
+
+ if (level & LLAPI_MSG_NO_ERRNO) {
+ vfprintf(stderr, fmt, ap);
+ if (!has_nl)
+ fprintf(stderr, "\n");
+ } else {
+ char *newfmt;
+
+ /* Remove trailing linefeed so error string can be appended.
+ * @fmt is a const string, so we can't modify it directly.
+ */
+ if (has_nl && (newfmt = strdup(fmt)))
+ *strrchr(newfmt, '\n') = '\0';
+ else
+ newfmt = (char *)fmt;
+
+ vfprintf(stderr, newfmt, ap);
+ if (newfmt != fmt)
+ free(newfmt);
fprintf(stderr, ": %s (%d)\n", strerror(err), err);
fprintf(stderr, ": %s (%d)\n", strerror(err), err);
}
static void info_callback_default(enum llapi_message_level level, int err,
}
static void info_callback_default(enum llapi_message_level level, int err,
if (*pbuf != NULL && data->ioc_len > max_len) {
llapi_error(LLAPI_MSG_ERROR, -EINVAL,
if (*pbuf != NULL && data->ioc_len > max_len) {
llapi_error(LLAPI_MSG_ERROR, -EINVAL,
- "pbuf = %p, ioc_len = %u, max_len = %d\n",
+ "pbuf = %p, ioc_len = %u, max_len = %d",
*pbuf, data->ioc_len, max_len);
return -EINVAL;
}
*pbuf, data->ioc_len, max_len);
return -EINVAL;
}
if (len > XATTR_SIZE_MAX - offsetof(struct lmv_foreign_md, lfm_value) ||
len <= 0) {
rc = -EINVAL;
if (len > XATTR_SIZE_MAX - offsetof(struct lmv_foreign_md, lfm_value) ||
len <= 0) {
rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc, "invalid LOV EA length %zu "
- "(must be 0 < len < %zu)\n", len,
- XATTR_SIZE_MAX -
- offsetof(struct lmv_foreign_md, lfm_value));
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "invalid LOV EA length %zu (must be 0 < len < %zu)",
+ len, XATTR_SIZE_MAX -
+ offsetof(struct lmv_foreign_md, lfm_value));
return rc;
}
lfm_size = len + offsetof(struct lmv_foreign_md, lfm_value);
return rc;
}
lfm_size = len + offsetof(struct lmv_foreign_md, lfm_value);
- if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename)) {
- char *errmsg = strerror(errno);
- llapi_err_noerrno(LLAPI_MSG_ERROR,
- "error on ioctl %#jx for '%s' (%d): %s",
- (uintmax_t)LL_IOC_LMV_SETSTRIPE, filename,
- fd, errmsg);
- }
+ if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename))
+ llapi_error(LLAPI_MSG_ERROR, errno,
+ "error on ioctl %#lx for '%s' (%d)",
+ (long)LL_IOC_LMV_SETSTRIPE, filename, fd);
out:
free(dirpath);
free(namepath);
out:
free(dirpath);
free(namepath);
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot open '%s': %s", mntdir,
- strerror(-rc));
+ "cannot open '%s'", mntdir);
ret = llapi_obd_statfs(path, type,
param->fp_obd_index, &stat_buf,
&uuid_buf);
ret = llapi_obd_statfs(path, type,
param->fp_obd_index, &stat_buf,
&uuid_buf);
- if (ret) {
- llapi_printf(LLAPI_MSG_NORMAL,
- "obd_uuid: %s failed %s ",
- param->fp_obd_uuid->uuid,
- strerror(errno));
- }
+ if (ret)
+ llapi_error(LLAPI_MSG_NORMAL, ret, "obd_uuid: %s failed",
+ param->fp_obd_uuid->uuid);
} else if (errno == EALREADY) {
if (param->fp_verbose & VERBOSE_DETAIL)
llapi_printf(LLAPI_MSG_NORMAL,
} else if (errno == EALREADY) {
if (param->fp_verbose & VERBOSE_DETAIL)
llapi_printf(LLAPI_MSG_NORMAL,
- "%s was migrated to MDT%d already\n",
+ "%s migrated to MDT%d already\n",
path, lmu->lum_stripe_offset);
ret = 0;
} else {
ret = -errno;
path, lmu->lum_stripe_offset);
ret = 0;
} else {
ret = -errno;
- llapi_error(LLAPI_MSG_ERROR, ret,
- "%s migrate failed: %s (%d)\n",
- path, strerror(-ret), ret);
+ llapi_error(LLAPI_MSG_ERROR, ret, "%s migrate failed",
+ path);
goto out;
}
} else if (param->fp_verbose & VERBOSE_DETAIL) {
goto out;
}
} else if (param->fp_verbose & VERBOSE_DETAIL) {
if (!printed) {
llapi_error(LLAPI_MSG_ERROR, -ESTALE,
if (!printed) {
llapi_error(LLAPI_MSG_ERROR, -ESTALE,
- "llapi_mv() is deprecated, use llapi_migrate_mdt()\n");
+ "%s() is deprecated, use llapi_migrate_mdt() instead",
+ __func__);
*/
comp_array[i].lrc_synced = true;
llapi_error(LLAPI_MSG_ERROR, written,
*/
comp_array[i].lrc_synced = true;
llapi_error(LLAPI_MSG_ERROR, written,
- "component %u not synced\n",
+ "component %u not synced",
comp_array[i].lrc_id);
if (rc2 == 0)
rc2 = (int)written;
comp_array[i].lrc_id);
if (rc2 == 0)
rc2 = (int)written;
rc = llapi_getname(mntpath, buf, sizeof(buf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
rc = llapi_getname(mntpath, buf, sizeof(buf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot get name for '%s'\n", mntpath);
+ "cannot get name for '%s'", mntpath);
rc = errno;
if (errno != EIO)
llapi_error(LLAPI_MSG_ERROR, rc,
rc = errno;
if (errno != EIO)
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: setting llite.%s.pcc=\"%s\"\n",
+ "error: setting llite.%s.pcc='%s'",
buf, cmd);
} else if (count < strlen(cmd)) { /* Truncate case */
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
buf, cmd);
} else if (count < strlen(cmd)) { /* Truncate case */
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
- "setting llite.%s.pcc=\"%s\": wrote only %zd\n",
+ "setting llite.%s.pcc='%s': wrote only %zd",
buf, cmd, count);
}
close(fd);
buf, cmd, count);
}
close(fd);
rc = llapi_getname(mntpath, pathbuf, sizeof(pathbuf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
rc = llapi_getname(mntpath, pathbuf, sizeof(pathbuf));
if (rc < 0) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "cannot get name for '%s'\n", mntpath);
+ "cannot get name for '%s'", mntpath);
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: opening '%s'\n",
+ "error: pccdev_get: opening '%s'",
path.gl_pathv[0]);
goto out_free_param;
}
path.gl_pathv[0]);
goto out_free_param;
}
if (buf == NULL) {
rc = -ENOMEM;
llapi_error(LLAPI_MSG_ERROR, rc,
if (buf == NULL) {
rc = -ENOMEM;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: allocating '%s' buffer\n",
+ "error: pccdev_get: allocating '%s' buffer",
path.gl_pathv[0]);
goto out_close;
}
path.gl_pathv[0]);
goto out_close;
}
rc = -errno;
if (errno != EIO) {
llapi_error(LLAPI_MSG_ERROR, rc,
rc = -errno;
if (errno != EIO) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: "
- "reading failed\n");
+ "error: pccdev_get: reading failed");
if (fwrite(buf, 1, count, stdout) != count) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
if (fwrite(buf, 1, count, stdout) != count) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error: get_param: write to stdout\n");
+ "error: get_param: write to stdout");
is_ext = is_fstype_ext(fd);
if (is_ext < 0) {
rc = is_ext;
is_ext = is_fstype_ext(fd);
if (is_ext < 0) {
rc = is_ext;
- printf("Unable to determine type of filesystem containing %s\n",
+ llapi_error(LLAPI_MSG_ERROR, -rc,
+ "Unable to determine filesystem type for %s",
file_size = st.st_size;
if (file_size < sizeof(**llog)) {
llapi_error(LLAPI_MSG_ERROR, rc,
file_size = st.st_size;
if (file_size < sizeof(**llog)) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "File too small for llog header: "
- "need %zd, size %lld\n",
+ "File too small for llog header: want=%zd got=%lld",
sizeof(**llog), file_size);
rc = -EIO;
goto out;
sizeof(**llog), file_size);
rc = -EIO;
goto out;
default:
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
default:
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
- "%s: unknown option '-%c'\n",
+ "%s: unknown option '%c'",
argv[0], optopt);
return rc;
case 'u':
argv[0], optopt);
return rc;
case 'u':
opt.o_mdtname, 0);
if (rc) {
llapi_error(LLAPI_MSG_ERROR, rc,
opt.o_mdtname, 0);
if (rc) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "unable to open changelog of MDT [%s]\n",
+ "unable to open changelog of MDT '%s'",
opt.o_mdtname);
return rc;
}
opt.o_mdtname);
return rc;
}
rc = llapi_changelog_fini(&chglog_hdlr);
if (rc) {
llapi_error(LLAPI_MSG_ERROR, rc,
rc = llapi_changelog_fini(&chglog_hdlr);
if (rc) {
llapi_error(LLAPI_MSG_ERROR, rc,
- "unable to close changelog of MDT [%s]",
+ "unable to close changelog of MDT '%s'",
opt.o_mdtname);
ret = rc;
return rc;
opt.o_mdtname);
ret = rc;
return rc;