Whamcloud - gitweb
b=13698 llapi_get_version
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 1614dd8..0855805 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -606,8 +606,19 @@ int llapi_search_mounts(const char *pathname, int index, char *mntdir,
 /* Given a path, find the corresponding Lustre fsname */
 int llapi_search_fsname(const char *pathname, char *fsname)
 {
+        char *path = (char*)pathname, buf[PATH_MAX + 1];
+
+        if (pathname[0] != '/') { /* Need a absolute path */
+                memset(buf, '\0', sizeof(buf));
+                if (realpath(pathname, buf) == NULL) {
+                        llapi_err(LLAPI_MSG_ERROR, "pathname '%s' cannot expand",
+                                  pathname);
+                        return -EINVAL;
+                }
+                path = buf;
+        }
         return get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL,
-                             (char *)pathname, -1);
+                             path, -1);
 }
 
 /* return the first file matching this pattern */
@@ -1350,11 +1361,18 @@ static int cb_ostlist(char *path, DIR *parent, DIR *d, void *data,
                       struct dirent64 *de)
 {
         struct find_param *param = (struct find_param *)data;
+        int ret;
 
         LASSERT(parent != NULL || d != NULL);
 
         /* Prepare odb. */
-        return setup_obd_uuid(d ? d : parent, path, param);
+        ret = setup_obd_uuid(d ? d : parent, path, param);
+
+        /* We don't want to actually traverse the directory tree,
+         * so return a positive value from sem_init to terminate
+         * the traversal before it starts.
+         */
+        return ret == 0 ? 1 : ret;
 }
 
 int llapi_ostlist(char *path, struct find_param *param)
@@ -1363,14 +1381,15 @@ int llapi_ostlist(char *path, struct find_param *param)
 }
 
 static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
+                                     struct lov_user_ost_data_v1 *objects,
                                      int is_dir, int verbose, int depth,
                                      char *pool_name)
 {
         char *prefix = is_dir ? "" : "lmm_";
         char nl = is_dir ? ' ' : '\n';
 
-        if (is_dir && lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) {
-                lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR;
+        if (is_dir && lum->lmm_object_seq == LOV_OBJECT_GROUP_DEFAULT) {
+                lum->lmm_object_seq = LOV_OBJECT_GROUP_CLEAR;
                 if (verbose & VERBOSE_DETAIL)
                         llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
         }
@@ -1381,8 +1400,8 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
         if ((verbose & VERBOSE_DETAIL) && !is_dir) {
                 llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic:          0x%08X\n",
                              lum->lmm_magic);
-                llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_gr:      "LPX64"\n",
-                             lum->lmm_object_gr);
+                llapi_printf(LLAPI_MSG_NORMAL, "lmm_seq:            "LPX64"\n",
+                             lum->lmm_object_seq);
                 llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id:      "LPX64"\n",
                              lum->lmm_object_id);
         }
@@ -1413,7 +1432,7 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
                         llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset:  ",
                                      prefix);
                 llapi_printf(LLAPI_MSG_NORMAL, "%u%c",
-                             lum->lmm_objects[0].l_ost_idx, nl);
+                             objects[0].l_ost_idx, nl);
         }
 
         if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
@@ -1442,7 +1461,7 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
         }
 
         if (obdstripe == 1)
-                lov_dump_user_lmm_header(lum, path, is_dir, header, depth,
+                lov_dump_user_lmm_header(lum, path, objects, is_dir, header, depth,
                                          pool_name);
 
         if (!is_dir && (header & VERBOSE_OBJID)) {
@@ -1453,7 +1472,7 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
                 for (i = 0; i < lum->lmm_stripe_count; i++) {
                         int idx = objects[i].l_ost_idx;
                         long long oid = objects[i].l_object_id;
-                        long long gr = objects[i].l_object_gr;
+                        long long gr = objects[i].l_object_seq;
                         if ((obdindex == OBD_NOT_FOUND) || (obdindex == idx))
                                 llapi_printf(LLAPI_MSG_NORMAL,
                                            "\t%6u\t%14llu\t%#13llx\t%14llu%s\n",
@@ -3233,5 +3252,49 @@ int llapi_copytool_free(struct hsm_action_list **hal)
         return 0;
 }
 
+int llapi_get_connect_flags(const char *mnt, __u64 *flags)
+{
+        DIR *root;
+        int rc;
 
+        root = opendir(mnt);
+        if (!root) {
+                llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
+                return -1;
+        }
 
+        rc = ioctl(dirfd(root), LL_IOC_GET_CONNECT_FLAGS, flags);
+        closedir(root);
+        if (rc < 0)
+                llapi_err(LLAPI_MSG_ERROR,
+                          "ioctl on %s for getting connect flags failed", mnt);
+        return rc;
+}
+
+int llapi_get_version(char *buffer, int buffer_size,
+                      char **version)
+{
+        int rc;
+        int fd;
+        struct obd_ioctl_data *data = (struct obd_ioctl_data *)buffer;
+
+        fd = open(OBD_DEV_PATH, O_RDONLY);
+        if (fd == -1)
+                return -errno;
+
+        memset(buffer, 0, buffer_size);
+        data->ioc_version = OBD_IOCTL_VERSION;
+        data->ioc_inllen1 = buffer_size - cfs_size_round(sizeof(*data));
+        data->ioc_inlbuf1 = buffer + cfs_size_round(sizeof(*data));
+        data->ioc_len = obd_ioctl_packlen(data);
+
+        rc = ioctl(fd, OBD_GET_VERSION, buffer);
+        if (rc == -1) {
+                rc = errno;
+                close(fd);
+                return -rc;
+        }
+        close(fd);
+        *version = data->ioc_bulk;
+        return 0;
+}