Whamcloud - gitweb
b=13698 llapi_get_version
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index e28f533..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.
  */
 /*
@@ -1361,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)
@@ -1374,6 +1381,7 @@ 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)
 {
@@ -1424,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)) {
@@ -1453,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)) {
@@ -3262,3 +3270,31 @@ int llapi_get_connect_flags(const char *mnt, __u64 *flags)
                           "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;
+}