int llapi_getname(const char *path, char *buf, size_t size)
{
- struct obd_uuid uuid_buf;
- char *uuid = uuid_buf.uuid;
- int rc, nr;
+ struct obd_uuid uuid_buf;
+ char *uuid = uuid_buf.uuid;
+ char *cfg_instance;
+ int rc, len, fsname_len;
- memset(&uuid_buf, 0, sizeof(uuid_buf));
- rc = llapi_file_get_lov_uuid(path, &uuid_buf);
- if (rc)
- return rc;
+ memset(&uuid_buf, 0, sizeof(uuid_buf));
+ rc = llapi_file_get_lov_uuid(path, &uuid_buf);
+ if (rc)
+ return rc;
- /* We want to turn lustre-clilov-ffff88002738bc00 into
- * lustre-ffff88002738bc00. */
+ /*
+ * We want to turn testfs-clilov-ffff88002738bc00 into
+ * testfs-ffff88002738bc00 in a portable way that doesn't depend
+ * on what is after "-clilov-" as it may change in the future.
+ * Unfortunately, the "fsname" part may contain a dash, so we
+ * can't just skip to the first dash, and the "instance" may be a
+ * UUID in the future, so we can't necessarily go to the last dash.
+ */
+ cfg_instance = strstr(uuid, "-clilov-");
+ if (!cfg_instance)
+ return -EINVAL;
- nr = snprintf(buf, size, "%.*s-%s",
- (int) (strlen(uuid) - 24), uuid,
- uuid + strlen(uuid) - 16);
+ fsname_len = cfg_instance - uuid;
+ cfg_instance += strlen("-clilov-");
+ len = snprintf(buf, size, "%.*s-%s", fsname_len, uuid, cfg_instance);
- if (nr >= size)
- rc = -ENAMETOOLONG;
+ if (len >= size)
+ rc = -ENAMETOOLONG;
- return rc;
+ return rc;
}
/**
}
if (verbose & VERBOSE_HASH_TYPE) {
- unsigned int type = lum->lum_hash_type;
+ unsigned int type = lum->lum_hash_type & LMV_HASH_TYPE_MASK;
+ unsigned int flags = lum->lum_hash_type & ~LMV_HASH_TYPE_MASK;
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
if (verbose & ~VERBOSE_HASH_TYPE)
llapi_printf(LLAPI_MSG_NORMAL, "%s",
mdt_hash_name[type]);
else
- llapi_printf(LLAPI_MSG_NORMAL, "%d",
- (int)type);
+ llapi_printf(LLAPI_MSG_NORMAL, "%#x", type);
+
+ if (flags & LMV_HASH_FLAG_MIGRATION)
+ llapi_printf(LLAPI_MSG_NORMAL, ",migrating");
+ if (flags & LMV_HASH_FLAG_DEAD)
+ llapi_printf(LLAPI_MSG_NORMAL, ",dead");
+ if (flags & LMV_HASH_FLAG_BAD_TYPE)
+ llapi_printf(LLAPI_MSG_NORMAL, ",bad_type");
+ if (flags & LMV_HASH_FLAG_LOST_LMV)
+ llapi_printf(LLAPI_MSG_NORMAL, ",lost_lmv");
separator = "\n";
+
}
if (verbose & VERBOSE_OBJID && lum->lum_magic != LMV_USER_MAGIC) {
int llapi_ping(char *obd_type, char *obd_name)
{
+ int flags = O_RDONLY;
+ char buf[1] = { 0 };
glob_t path;
- char buf[1];
int rc, fd;
rc = cfs_get_param_paths(&path, "%s/%s/ping",
obd_type, obd_name);
if (rc != 0)
return -errno;
-
- fd = open(path.gl_pathv[0], O_WRONLY);
+retry_open:
+ fd = open(path.gl_pathv[0], flags);
if (fd < 0) {
+ if (errno == EACCES && flags == O_RDONLY) {
+ flags = O_WRONLY;
+ goto retry_open;
+ }
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s",
path.gl_pathv[0]);
goto failed;
}
- /* 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 (flags == O_RDONLY)
+ rc = read(fd, buf, sizeof(buf));
+ else
+ rc = write(fd, buf, sizeof(buf));
if (rc < 0)
rc = -errno;
close(fd);