Whamcloud - gitweb
*** empty log message ***
authoradilger <adilger>
Wed, 9 Jul 2008 19:49:29 +0000 (19:49 +0000)
committeradilger <adilger>
Wed, 9 Jul 2008 19:49:29 +0000 (19:49 +0000)
lustre/utils/liblustreapi.c

index 0043904..75e7b28 100644 (file)
@@ -24,7 +24,9 @@
  */
 
 /* for O_DIRECTORY */
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -1054,44 +1056,51 @@ static int cb_find_init(char *path, DIR *parent, DIR *dir,
 
         ret = 0;
         /* Request MDS for the stat info. */
-        if (param->have_fileinfo == 0) {
+        if (!decision) {
                 if (dir) {
                         /* retrieve needed file info */
                         ret = ioctl(dirfd(dir), LL_IOC_MDC_GETINFO,
                                     (void *)param->lmd);
-                } else {
+                } else /* if (parent) LASSERT() above */ {
                         char *fname = strrchr(path, '/');
                         fname = (fname == NULL ? path : fname + 1);
 
                         /* retrieve needed file info */
                         strncpy((char *)param->lmd, fname, param->lumlen);
                         ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO,
-                                   (void *)param->lmd);
+                                    (void *)param->lmd);
                 }
-        }
 
-        if (ret) {
-                if (errno == ENOTTY) {
-                        /* ioctl is not supported, it is not a lustre fs.
-                         * Do the regular lstat(2) instead. */
-                        lustre_fs = 0;
-                        ret = lstat_f(path, st);
-                        if (ret) {
-                                llapi_err(LLAPI_MSG_ERROR, 
-                                          "error: %s: lstat failed for %s",
-                                          __FUNCTION__, path);
+                if (ret) {
+                        if (errno == ENOTTY) {
+                                /* ioctl is not supported, it is not a lustre
+                                 * fs. Do the regular lstat(2) instead. */
+                                lustre_fs = 0;
+                                ret = lstat_f(path, st);
+                                if (ret) {
+                                        llapi_err(LLAPI_MSG_ERROR,
+                                                "error: %s: stat failed for %s",
+                                                __FUNCTION__, path);
+                                        return ret;
+                                }
+                        } else {
+                                llapi_err(LLAPI_MSG_ERROR,
+                                          "error: %s: %s failed for %s",
+                                          __FUNCTION__,
+                                          dir ? "LL_IOC_MDC_GETINFO" :
+                                                "IOC_MDC_GETFILEINFO", path);
                                 return ret;
                         }
-                } else if (errno == ENOENT) {
-                        llapi_err(LLAPI_MSG_WARN, 
-                                  "warning: %s: %s does not exist",
-                                  __FUNCTION__, path);
-                        goto decided;
+                }
+        }
+
+        if (param->type && !checked_type) {
+                if ((st->st_mode & S_IFMT) == param->type) {
+                        if (param->exclude_type)
+                                goto decided;
                 } else {
-                        llapi_err(LLAPI_MSG_ERROR, "error: %s: %s failed for %s",
-                                  __FUNCTION__, dir ? "LL_IOC_MDC_GETINFO" :
-                                  "IOC_MDC_GETFILEINFO", path);
-                        return ret;
+                        if (!param->exclude_type)
+                                goto decided;
                 }
         }
 
@@ -1120,8 +1129,7 @@ static int cb_find_init(char *path, DIR *parent, DIR *dir,
                 int for_mds;
 
                 for_mds = lustre_fs ? (S_ISREG(st->st_mode) &&
-                                       param->lmd->lmd_lmm.lmm_stripe_count)
-                                    : 0;
+                                       param->lmd->lmd_lmm.lmm_stripe_count) :0;
                 decision = find_time_check(st, param, for_mds);
                 if (decision == -1)
                         goto decided;
@@ -1199,7 +1207,7 @@ obd_matches:
                 if (dir) {
                         ret = ioctl(dirfd(dir), IOC_LOV_GETINFO,
                                     (void *)param->lmd);
-                } else if (parent) {
+                } else /* if (parent) LASSERT above */ {
                         ret = ioctl(dirfd(parent), IOC_LOV_GETINFO,
                                     (void *)param->lmd);
                 }
@@ -1265,7 +1273,7 @@ int llapi_find(char *path, struct find_param *param)
                 return -EINVAL;
         }
 
-        buf = (char *)malloc(PATH_MAX + 1);
+        buf = (char *)malloc(PATH_MAX);
         if (!buf)
                 return -ENOMEM;
 
@@ -1277,8 +1285,8 @@ int llapi_find(char *path, struct find_param *param)
 
         param->depth = 0;
 
-        strncpy(buf, path, PATH_MAX + 1);
-        ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_find_init,
+        strncpy(buf, path, PATH_MAX);
+        ret = llapi_semantic_traverse(buf, PATH_MAX, NULL, cb_find_init,
                                       cb_common_fini, param, NULL);
 
         find_param_fini(param);
@@ -1353,14 +1361,14 @@ int llapi_getstripe(char *path, struct find_param *param)
         char *buf;
         int ret = 0, len = strlen(path);
 
-        if (len > PATH_MAX) {
-                llapi_err(LLAPI_MSG_ERROR, 
-                          "%s: Path name '%s' is too long",
-                          __FUNCTION__, path);
+        if (len >= PATH_MAX) {
+                llapi_err(LLAPI_MSG_ERROR,
+                          "%s: Path name '%s' is too long (%d bytes)",
+                          __FUNCTION__, path, len);
                 return -EINVAL;
         }
 
-        buf = (char *)malloc(PATH_MAX + 1);
+        buf = (char *)malloc(PATH_MAX);
         if (!buf)
                 return -ENOMEM;
 
@@ -1372,8 +1380,8 @@ int llapi_getstripe(char *path, struct find_param *param)
 
         param->depth = 0;
 
-        strncpy(buf, path, PATH_MAX + 1);
-        ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_getstripe,
+        strncpy(buf, path, PATH_MAX);
+        ret = llapi_semantic_traverse(buf, PATH_MAX, NULL, cb_getstripe,
                                       cb_common_fini, param, NULL);
         find_param_fini(param);
         free(buf);
@@ -1698,13 +1706,14 @@ int llapi_quotachown(char *path, int flag)
         char *buf;
         int ret = 0, len = strlen(path);
 
-        if (len > PATH_MAX) {
-                llapi_err(LLAPI_MSG_ERROR, "%s: Path name '%s' is too long",
-                          __FUNCTION__, path);
+        if (len >= PATH_MAX) {
+                llapi_err(LLAPI_MSG_ERROR,
+                          "%s: Path name '%s' is too long (%d bytes)",
+                          __FUNCTION__, path, len);
                 return -EINVAL;
         }
 
-        buf = (char *)malloc(PATH_MAX + 1);
+        buf = (char *)malloc(PATH_MAX);
         if (!buf)
                 return -ENOMEM;
 
@@ -1717,8 +1726,8 @@ int llapi_quotachown(char *path, int flag)
         if (ret)
                 goto out;
 
-        strncpy(buf, path, PATH_MAX + 1);
-        ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_quotachown,
+        strncpy(buf, path, PATH_MAX);
+        ret = llapi_semantic_traverse(buf, PATH_MAX, NULL, cb_quotachown,
                                       NULL, &param, NULL);
 out:
         find_param_fini(&param);