Whamcloud - gitweb
Branch HEAD
authorbobijam <bobijam>
Tue, 1 Jul 2008 03:38:57 +0000 (03:38 +0000)
committerbobijam <bobijam>
Tue, 1 Jul 2008 03:38:57 +0000 (03:38 +0000)
b=12653
i=green, johann
Description: sanity test 65a fails if stripecount of -1 is set
Details    : handle -1 striping on filesystem in ll_dirstripe_verify

lustre/ChangeLog
lustre/include/lustre/liblustreapi.h
lustre/tests/Makefile.am
lustre/tests/ll_dirstripe_verify.c
lustre/utils/liblustreapi.c

index e33723b..2204e41 100644 (file)
@@ -13,6 +13,11 @@ tbd  Sun Microsystems, Inc.
         removed cwd "./" (refer to Bugzilla 14399).
 
 Severity   : normal
         removed cwd "./" (refer to Bugzilla 14399).
 
 Severity   : normal
+Bugzilla   : 12653
+Description: sanity test 65a fails if stripecount of -1 is set
+Details    : handle -1 striping on filesystem in ll_dirstripe_verify
+
+Severity   : normal
 Bugzilla   : 14742
 Frequency  : rare
 Description: ASSERTION(CheckWriteback(page,cmd)) failed
 Bugzilla   : 14742
 Frequency  : rare
 Description: ASSERTION(CheckWriteback(page,cmd)) failed
index 0e5b2bf..235e461 100644 (file)
@@ -98,6 +98,8 @@ extern int llapi_obd_statfs(char *path, __u32 type, __u32 index,
 extern int llapi_ping(char *obd_type, char *obd_name);
 extern int llapi_target_check(int num_types, char **obd_types, char *dir);
 extern int llapi_catinfo(char *dir, char *keyword, char *node_name);
 extern int llapi_ping(char *obd_type, char *obd_name);
 extern int llapi_target_check(int num_types, char **obd_types, char *dir);
 extern int llapi_catinfo(char *dir, char *keyword, char *node_name);
+extern int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid);
+extern int llapi_file_get_lov_fuuid(int fd, struct obd_uuid *lov_uuid);
 extern int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count);
 extern int llapi_is_lustre_mnttype(const char *type);
 extern int parse_size(char *optarg, unsigned long long *size,
 extern int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count);
 extern int llapi_is_lustre_mnttype(const char *type);
 extern int parse_size(char *optarg, unsigned long long *size,
index a10553d..4d4017b 100644 (file)
@@ -56,6 +56,9 @@ LIBLUSTREAPI := $(top_builddir)/lustre/utils/liblustreapi.a
 ll_getstripe_info_LDADD=$(LIBLUSTREAPI)
 multiop_LDADD=$(LIBLUSTREAPI)
 
 ll_getstripe_info_LDADD=$(LIBLUSTREAPI)
 multiop_LDADD=$(LIBLUSTREAPI)
 
+ll_dirstripe_verify_SOURCES= ll_dirstripe_verify.c
+ll_dirstripe_verify_LDADD= -L$(top_builddir)/lustre/utils -llustreapi
+
 if MPITESTS
 LAM_LD_FLAGS=-L/opt/lam/lib -lmpi -llam -lpthread
 write_append_truncate_SOURCES=write_append_truncate.c
 if MPITESTS
 LAM_LD_FLAGS=-L/opt/lam/lib -lmpi -llam -lpthread
 write_append_truncate_SOURCES=write_append_truncate.c
index 84d0d08..b02d5ac 100644 (file)
 #include <liblustre.h>
 #include <obd.h>
 #include <lustre_lib.h>
 #include <liblustre.h>
 #include <obd.h>
 #include <lustre_lib.h>
-#include <lustre/lustre_user.h>
+#include <lustre/liblustreapi.h>
 #include <obd_lov.h>
 
 #include <lnet/lnetctl.h>
 
 
 #define MAX_LOV_UUID_COUNT      1000
 #include <obd_lov.h>
 
 #include <lnet/lnetctl.h>
 
 
 #define MAX_LOV_UUID_COUNT      1000
+union {
+        struct obd_uuid uuid;
+        char name[0];
+} lov;
+#define lov_uuid lov.uuid
+#define lov_name lov.name
 
 /* Returns bytes read on success and a negative value on failure.
  * If zero bytes are read it will be treated as failure as such
 
 /* Returns bytes read on success and a negative value on failure.
  * If zero bytes are read it will be treated as failure as such
@@ -40,18 +46,18 @@ int read_proc_entry(char *proc_path, char *buf, int len)
 
         fd = open(proc_path, O_RDONLY);
         if (fd == -1) {
 
         fd = open(proc_path, O_RDONLY);
         if (fd == -1) {
-                fprintf(stderr, "open('%s') failed: %s\n",
-                        proc_path, strerror(errno));
+                llapi_err(LLAPI_MSG_ERROR, "open('%s') failed: %s\n",
+                          proc_path);
                 return -2;
         }
 
         rc = read(fd, buf, len - 1);
         if (rc < 0) {
                 return -2;
         }
 
         rc = read(fd, buf, len - 1);
         if (rc < 0) {
-                fprintf(stderr, "read('%s') failed: %s\n",
-                        proc_path, strerror(errno));
+                llapi_err(LLAPI_MSG_ERROR, "read('%s') failed: %s\n",proc_path);
                 rc = -3;
         } else if (rc == 0) {
                 rc = -3;
         } else if (rc == 0) {
-                fprintf(stderr, "read('%s') zero bytes\n", proc_path);
+                llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
+                          "read('%s') zero bytes\n", proc_path);
                 rc = -4;
         } else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
                 buf[rc - 1] = '\0'; /* Remove trailing newline */
                 rc = -4;
         } else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
                 buf[rc - 1] = '\0'; /* Remove trailing newline */
@@ -64,7 +70,7 @@ int read_proc_entry(char *proc_path, char *buf, int len)
 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
             struct lov_user_md *lum_file2)
 {
 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
             struct lov_user_md *lum_file2)
 {
-        int stripe_count = 0;
+        int stripe_count = 0, min_stripe_count = 0, def_stripe_count = 1;
         int stripe_size = 0;
         int stripe_offset = -1;
         int ost_count;
         int stripe_size = 0;
         int stripe_offset = -1;
         int ost_count;
@@ -76,44 +82,63 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
 
         fp = popen("\\ls -d  /proc/fs/lustre/lov/*clilov* | head -1", "r");
         if (!fp) {
 
         fp = popen("\\ls -d  /proc/fs/lustre/lov/*clilov* | head -1", "r");
         if (!fp) {
-                fprintf(stderr, "open(lustre/lov/*clilov*) failed: %s\n", 
-                        strerror(errno));
+                llapi_err(LLAPI_MSG_ERROR,
+                          "open(lustre/lov/*clilov*) failed: %s\n");
                 return 2;
         }
                 return 2;
         }
-        if (fscanf(fp, "%s", lov_path) < 1) { 
-                fprintf(stderr, "read(lustre/lov/*clilov*) failed: %s\n",
-                        strerror(errno));
+        if (fscanf(fp, "%s", lov_path) < 1) {
+                llapi_err(LLAPI_MSG_ERROR,
+                          "read(lustre/lov/*clilov*) failed: %s\n");
                 pclose(fp);
                 return 3;
         }
         pclose(fp);
 
                 pclose(fp);
                 return 3;
         }
         pclose(fp);
 
-        if (lum_dir == NULL) {
-                snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
-                         lov_path);
-                if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
-                        return 5;
+        snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
+                 lov_path);
+        if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
+                return 5;
+        def_stripe_count = (short)atoi(buf);
 
 
-                stripe_count = (int)strtoul(buf, NULL, 10);;
+        snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
+        if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
+                return 6;
+        ost_count = atoi(buf);
+
+        if (lum_dir == NULL) {
+                stripe_count = def_stripe_count;
+                min_stripe_count = -1;
         } else {
                 stripe_count = (signed short)lum_dir->lmm_stripe_count;
         } else {
                 stripe_count = (signed short)lum_dir->lmm_stripe_count;
+                printf("dir stripe %d, ", stripe_count);
+                min_stripe_count = 1;
         }
         }
-        if (stripe_count == 0)
-                stripe_count = 1;
 
 
-        snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
-        if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
-                return 6;
+        printf("default stripe %d, ost count %d\n",
+               def_stripe_count, ost_count);
 
 
-        ost_count = atoi(buf);
-        stripe_count = stripe_count > 0 ? stripe_count : ost_count;
+        if (stripe_count == 0) {
+                min_stripe_count = -1;
+                stripe_count = 1;
+        }
+
+        stripe_count = (stripe_count > 0 && stripe_count <= ost_count) ?
+                                                stripe_count : ost_count;
+        min_stripe_count = min_stripe_count > 0 ? stripe_count :
+                                                ((stripe_count + 1) / 2);
 
 
-        if (lum_file1->lmm_stripe_count != stripe_count) {
-                fprintf(stderr, "file1 stripe count %d != dir %d\n",
-                        lum_file1->lmm_stripe_count, stripe_count);
+        if (lum_file1->lmm_stripe_count != stripe_count ||
+            lum_file1->lmm_stripe_count < min_stripe_count) {
+                llapi_err(LLAPI_MSG_ERROR, "file1 stripe count %d != dir %d\n",
+                          lum_file1->lmm_stripe_count, stripe_count);
                 return 7;
         }
 
                 return 7;
         }
 
+        if (lum_file1->lmm_stripe_count < stripe_count)
+                llapi_err(LLAPI_MSG_WARN, "warning: file1 used fewer stripes"
+                          " %d < dir %d (likely due to bug 4900)\n",
+                          lum_file1->lmm_stripe_count, stripe_count);
+
         if (lum_dir != NULL)
                 stripe_size = (int)lum_dir->lmm_stripe_size;
         if (stripe_size == 0) {
         if (lum_dir != NULL)
                 stripe_size = (int)lum_dir->lmm_stripe_size;
         if (stripe_size == 0) {
@@ -126,8 +151,8 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
         }
 
         if (lum_file1->lmm_stripe_size != stripe_size) {
         }
 
         if (lum_file1->lmm_stripe_size != stripe_size) {
-                fprintf(stderr, "file1 stripe size %d != dir %d\n",
-                        lum_file1->lmm_stripe_size, stripe_size);
+                llapi_err(LLAPI_MSG_ERROR, "file1 stripe size %d != dir %d\n",
+                          lum_file1->lmm_stripe_size, stripe_size);
                 return 8;
         }
 
                 return 8;
         }
 
@@ -137,10 +162,11 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
                 for (i = 0; i < stripe_count; i++)
                         if (lum_file1->lmm_objects[i].l_ost_idx !=
                             (stripe_offset + i) % ost_count) {
                 for (i = 0; i < stripe_count; i++)
                         if (lum_file1->lmm_objects[i].l_ost_idx !=
                             (stripe_offset + i) % ost_count) {
-                                fprintf(stderr, "warning: file1 non-sequential "
-                                        "stripe[%d] %d != %d\n", i,
-                                        lum_file1->lmm_objects[i].l_ost_idx,
-                                        (stripe_offset + i) % ost_count);
+                                llapi_err(LLAPI_MSG_WARN,
+                                          "warning: file1 non-sequential "
+                                          "stripe[%d] %d != %d\n", i,
+                                          lum_file1->lmm_objects[i].l_ost_idx,
+                                          (stripe_offset + i) % ost_count);
                         }
         } else if (lum_file2 != NULL) {
                 int next, idx, stripe = stripe_count - 1;
                         }
         } else if (lum_file2 != NULL) {
                 int next, idx, stripe = stripe_count - 1;
@@ -148,10 +174,10 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
                        ost_count;
                 idx = lum_file2->lmm_objects[0].l_ost_idx;
                 if (idx != next) {
                        ost_count;
                 idx = lum_file2->lmm_objects[0].l_ost_idx;
                 if (idx != next) {
-                        fprintf(stderr, "warning: non-sequential "
-                                "file1 stripe[%d] %d != file2 stripe[0] %d\n",
-                                stripe,
-                                lum_file1->lmm_objects[stripe].l_ost_idx, idx);
+                        llapi_err(LLAPI_MSG_WARN, "warning: non-sequential "
+                                  "file1 stripe[%d] %d != file2 stripe[0] %d\n",
+                                  stripe, lum_file1->lmm_objects[stripe].l_ost_idx,
+                                  idx);
                 }
         }
 
                 }
         }
 
@@ -164,69 +190,81 @@ int main(int argc, char **argv)
         struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
         int rc;
         int lum_size;
         struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
         int rc;
         int lum_size;
-        char *fname;
 
         if (argc < 3) {
 
         if (argc < 3) {
-                fprintf(stderr, "Usage: %s <dirname> <filename1> [filename2]\n",
-                        argv[0]);
+                llapi_err(LLAPI_MSG_ERROR,
+                          "Usage: %s <dirname> <filename1> [filename2]\n",
+                          argv[0]);
                 return 1;
         }
 
         dir = opendir(argv[1]);
         if (dir == NULL) {
                 return 1;
         }
 
         dir = opendir(argv[1]);
         if (dir == NULL) {
-                fprintf(stderr, "%s opendir failed: %s\n", argv[1], 
-                        strerror(errno));
-                return errno;
+                rc = errno;
+                llapi_err(LLAPI_MSG_ERROR,
+                          "error: %s opendir failed\n", argv[1]);
+                return rc;
         }
 
         lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
         if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
         }
 
         lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
         if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
-                fprintf(stderr, "unable to allocate memory for ioctl's");
-                return errno;
+                rc = ENOMEM;
+                llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d bytes "
+                          "for dir EA", lum_size);
+                goto cleanup;
         }
 
         }
 
-        rc = ioctl(dirfd(dir), LL_IOC_LOV_GETSTRIPE, lum_dir);
+        rc = llapi_file_get_stripe(argv[1], lum_dir);
         if (rc) {
                 if (errno == ENODATA) {
                         free(lum_dir);
                         lum_dir = NULL;
                 } else {
                         rc = errno;
         if (rc) {
                 if (errno == ENODATA) {
                         free(lum_dir);
                         lum_dir = NULL;
                 } else {
                         rc = errno;
+                        llapi_err(LLAPI_MSG_ERROR,
+                                  "error: can't get EA for %s\n", argv[1]);
                         goto cleanup;
                 }
         }
 
                         goto cleanup;
                 }
         }
 
-        if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
-                fprintf(stderr, "unable to allocate memory for ioctl's");
+        /* XXX should be llapi_lov_getname() */
+        rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
+        if (rc) {
                 rc = errno;
                 rc = errno;
-                goto cleanup;
+                llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name for %s\n",
+                          argv[1]);
+                return rc;
         }
 
         }
 
-        fname = strrchr(argv[2], '/');
-        fname = (fname == NULL ? argv[2] : fname + 1);
+        if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
+                rc = ENOMEM;
+                llapi_err(LLAPI_MSG_ERROR,
+                          "error: can't allocate %d bytes for EA\n", lum_size);
+                goto cleanup;
+        }
 
 
-        strncpy((char *)lum_file1, fname, lum_size);
-        rc = ioctl(dirfd(dir), IOC_MDC_GETFILESTRIPE, lum_file1);
+        rc = llapi_file_get_stripe(argv[2], lum_file1);
         if (rc) {
                 rc = errno;
         if (rc) {
                 rc = errno;
+                llapi_err(LLAPI_MSG_ERROR,
+                          "error: unable to get EA for %s\n", argv[2]);
                 goto cleanup;
         }
 
         if (argc == 4) {
                 lum_file2 = (struct lov_user_md *)malloc(lum_size);
                 if (lum_file2 == NULL) {
                 goto cleanup;
         }
 
         if (argc == 4) {
                 lum_file2 = (struct lov_user_md *)malloc(lum_size);
                 if (lum_file2 == NULL) {
-                        fprintf(stderr,
-                                "unable to allocate memory for ioctl's");
-                        rc = errno;
+                        rc = ENOMEM;
+                        llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d "
+                                  "bytes for file2 EA\n", lum_size);
                         goto cleanup;
                 }
 
                         goto cleanup;
                 }
 
-                fname = strrchr(argv[3], '/');
-                fname = (fname == NULL ? argv[3] : fname + 1);
-                strncpy((char *)lum_file2, fname, lum_size);
-                rc = ioctl(dirfd(dir), IOC_MDC_GETFILESTRIPE, lum_file2);
+                rc = llapi_file_get_stripe(argv[3], lum_file2);
                 if (rc) {
                         rc = errno;
                 if (rc) {
                         rc = errno;
+                        llapi_err(LLAPI_MSG_ERROR,
+                                  "error: can't get EA for %s\n", argv[3]);
                         goto cleanup;
                 }
         }
                         goto cleanup;
                 }
         }
@@ -234,6 +272,7 @@ int main(int argc, char **argv)
         rc = compare(lum_dir, lum_file1, lum_file2);
 
 cleanup:
         rc = compare(lum_dir, lum_file1, lum_file2);
 
 cleanup:
+        closedir(dir);
         if (lum_dir != NULL)
                 free(lum_dir);
         if (lum_file1 != NULL)
         if (lum_dir != NULL)
                 free(lum_dir);
         if (lum_file1 != NULL)
index b9328e5..5e56d7f 100644 (file)
@@ -322,6 +322,34 @@ static void find_param_fini(struct find_param *param)
                 free(param->lmd);
 }
 
                 free(param->lmd);
 }
 
+int llapi_file_get_lov_fuuid(int fd, struct obd_uuid *lov_name)
+{
+        int rc = ioctl(fd, OBD_IOC_GETNAME, lov_name);
+        if (rc) {
+                rc = errno;
+                llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name.");
+        }
+        return rc;
+}
+
+int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid)
+{
+        int fd, rc;
+
+        fd = open(path, O_RDONLY);
+        if (fd < 0) {
+                rc = errno;
+                llapi_err(LLAPI_MSG_ERROR, "error opening %s\n", path);
+                return rc;
+        }
+
+        rc = llapi_file_get_lov_fuuid(fd, lov_uuid);
+
+        close(fd);
+
+        return rc;
+}
+
 /*
  * If uuidp is NULL, return the number of available obd uuids.
  * If uuidp is non-NULL, then it will return the uuids of the obds. If
 /*
  * If uuidp is NULL, return the number of available obd uuids.
  * If uuidp is non-NULL, then it will return the uuids of the obds. If
@@ -330,22 +358,19 @@ static void find_param_fini(struct find_param *param)
  */
 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
 {
  */
 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
 {
-        char lov_name[sizeof(struct obd_uuid)];
+        struct obd_uuid lov_name;
         char buf[1024];
         FILE *fp;
         int rc = 0, index = 0;
 
         /* Get the lov name */
         char buf[1024];
         FILE *fp;
         int rc = 0, index = 0;
 
         /* Get the lov name */
-        rc = ioctl(fd, OBD_IOC_GETNAME, (void *) lov_name);
-        if (rc) {
-                rc = errno;
-                llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name");
+        rc = llapi_file_get_lov_fuuid(fd, &lov_name);
+        if (rc)
                 return rc;
                 return rc;
-        }
 
         /* Now get the ost uuids from /proc */
         snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
 
         /* Now get the ost uuids from /proc */
         snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
-                 lov_name);
+                 lov_name.uuid);
         fp = fopen(buf, "r");
         if (fp == NULL) {
                 rc = errno;
         fp = fopen(buf, "r");
         if (fp == NULL) {
                 rc = errno;
@@ -374,13 +399,14 @@ int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
  * returned in param->obdindex */
 static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
 {
  * returned in param->obdindex */
 static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
 {
+        struct obd_uuid lov_uuid;
         char uuid[sizeof(struct obd_uuid)];
         char buf[1024];
         FILE *fp;
         int rc = 0, index;
 
         /* Get the lov name */
         char uuid[sizeof(struct obd_uuid)];
         char buf[1024];
         FILE *fp;
         int rc = 0, index;
 
         /* Get the lov name */
-        rc = ioctl(dirfd(dir), OBD_IOC_GETNAME, (void *)uuid);
+        rc = llapi_file_get_lov_fuuid(dirfd(dir), &lov_uuid);
         if (rc) {
                 if (errno != ENOTTY) {
                         rc = errno;
         if (rc) {
                 if (errno != ENOTTY) {
                         rc = errno;
@@ -396,7 +422,7 @@ static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
 
         /* Now get the ost uuids from /proc */
         snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
 
         /* Now get the ost uuids from /proc */
         snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
-                 uuid);
+                 lov_uuid.uuid);
         fp = fopen(buf, "r");
         if (fp == NULL) {
                 rc = errno;
         fp = fopen(buf, "r");
         if (fp == NULL) {
                 rc = errno;