From 71c9168c06217e42674c58b10a46fc0c3742992d Mon Sep 17 00:00:00 2001
From: youfeng <youfeng>
Date: Tue, 24 Feb 2004 06:56:16 +0000
Subject: [PATCH] b 2295 r Adilger

move defination IOC_MDC_GETSTRIPE and declaration op_create_file() to lustre_user.h cause it is needed for user-space apps.

add a funcation int get_file_stripe(char *path, struct lov_user_md *lum) in liblustreapi.c, which is used by user apps want to get Lustre files' stripe info
---
 lustre/include/linux/lustre_user.h |  7 +++++
 lustre/include/linux/obd.h         |  1 -
 lustre/utils/lfs.c                 |  3 +--
 lustre/utils/liblustreapi.c        | 43 ++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/lustre/include/linux/lustre_user.h b/lustre/include/linux/lustre_user.h
index 2eba4859f9..9866acf5c0 100644
--- a/lustre/include/linux/lustre_user.h
+++ b/lustre/include/linux/lustre_user.h
@@ -25,6 +25,9 @@
 #define _LUSTRE_USER_H
 #include <asm/types.h>
 
+#define IOC_MDC_TYPE         'i'
+#define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *)
+
 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
@@ -65,4 +68,8 @@ struct lov_user_md_v1 {           /* LOV EA user data (host-endian) */
         struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
 } __attribute__((packed));
 
+extern int op_create_file(char *name, long stripe_size, int stripe_offset,
+                          int stripe_count);
+extern int get_file_stripe(char *path, struct lov_user_md *lum);
+
 #endif /* _LUSTRE_USER_H */
diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h
index e911174b3e..365708bd0a 100644
--- a/lustre/include/linux/obd.h
+++ b/lustre/include/linux/obd.h
@@ -18,7 +18,6 @@
 #define IOC_MDC_TYPE         'i'
 #define IOC_MDC_MIN_NR       20
 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
-#define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *)
 #define IOC_MDC_MAX_NR       50
 
 #ifdef __KERNEL__
diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c
index a41f7a7aaa..4685e46673 100644
--- a/lustre/utils/lfs.c
+++ b/lustre/utils/lfs.c
@@ -34,12 +34,11 @@
 
 #include <liblustre.h>
 #include <linux/lustre_idl.h>
+#include <linux/lustre_user.h>
 
 #include "parser.h"
 #include "obdctl.h"
 
-extern int op_create_file(char *name, long stripe_size, int stripe_offset,
-                int stripe_count);
 extern int op_find(char *path, struct obd_uuid *obduuid, int recursive,
                 int verbose, int quiet);
 extern int op_check(int type_num, char **obd_type_p, char *dir);
diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c
index 0cf4489b6d..bb5bbe12b7 100644
--- a/lustre/utils/liblustreapi.c
+++ b/lustre/utils/liblustreapi.c
@@ -292,6 +292,49 @@ void lov_dump_user_lmm(struct find_param *param, char *dname, char *fname)
         }
 }
 
+int get_file_stripe(char *path, struct lov_user_md *lum)
+{
+        char *dname, *fname;
+        int fd, rc = 0;
+
+        fname = strrchr(path, '/');
+
+        /* It should be a file (or other non-directory) */
+        if (fname == NULL) {
+                dname = (char *)malloc(2);
+                if (dname == NULL)
+                        return ENOMEM;
+                strcpy(dname, ".");
+                fname = path;
+        } else {
+                dname = (char *)malloc(fname - path + 1);
+                if (dname == NULL)
+                        return ENOMEM;
+                strncpy(dname, path, fname - path);
+                dname[fname - path + 1] = '\0';
+                fname++;
+        }
+
+        if ((fd = open(dname, O_RDONLY)) == -1) {
+                free(dname);
+                return errno;
+        }
+
+        strncpy((char *)lum, fname, sizeof(*lum));
+        if (ioctl(fd, IOC_MDC_GETSTRIPE, (void *)lum) == -1) {
+                close(fd);
+                free(dname);
+                return errno;
+        }
+
+        if (close(fd) == -1)
+                rc = errno;
+
+        free(dname);
+
+        return rc;
+}
+
 static int process_file(DIR *dir, char *dname, char *fname,
                          struct find_param *param)
 {
-- 
GitLab