*
*/
-
/* for O_DIRECTORY */
#define _GNU_SOURCE
#include <unistd.h>
#endif
-#include <lnet/lnetctl.h>
-
#include <liblustre.h>
+#include <lnet/lnetctl.h>
#include <obd.h>
#include <lustre_lib.h>
#include <obd_lov.h>
fprintf(stderr, ": %s (%d)\n", strerror(tmp_errno), tmp_errno);
}
-int llapi_file_create(const char *name, unsigned long stripe_size, int stripe_offset,
- int stripe_count, int stripe_pattern)
+int llapi_file_open(const char *name, int flags, int mode,
+ unsigned long stripe_size, int stripe_offset,
+ int stripe_count, int stripe_pattern)
{
struct lov_user_md lum = { 0 };
int fd, rc = 0;
int isdir = 0;
int page_size;
- fd = open(name, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
- if (errno == EISDIR) {
+ fd = open(name, flags | O_LOV_DELAY_CREATE, mode);
+ if (fd < 0 && errno == EISDIR) {
fd = open(name, O_DIRECTORY | O_RDONLY);
isdir++;
}
if (errno != EEXIST && errno != EALREADY)
errmsg = strerror(errno);
- rc = -errno;
fprintf(stderr, "error on ioctl "LPX64" for '%s' (%d): %s\n",
(__u64)LL_IOC_LOV_SETSTRIPE, name, fd, errmsg);
}
out:
- if (close(fd) < 0) {
- if (rc == 0)
- rc = -errno;
- err_msg("error on close for '%s' (%d)", name, fd);
+ if (rc) {
+ close(fd);
+ fd = rc;
}
- return rc;
+
+ return fd;
+}
+
+int llapi_file_create(const char *name, unsigned long stripe_size,
+ int stripe_offset, int stripe_count, int stripe_pattern)
+{
+ int fd;
+
+ fd = llapi_file_open(name, O_CREAT | O_WRONLY, 0644, stripe_size,
+ stripe_offset, stripe_count, stripe_pattern);
+ if (fd < 0)
+ return fd;
+
+ close(fd);
+ return 0;
}
typedef int (semantic_func_t)(char *path, DIR *parent, DIR *d, void *data);
return parent;
}
-static int llapi_semantic_traverse(char *path, DIR *parent,
+static int llapi_semantic_traverse(char *path, int size, DIR *parent,
semantic_func_t sem_init,
semantic_func_t sem_fini, void *data)
{
continue;
path[len] = 0;
+ if ((len + dent->d_reclen + 2) > size) {
+ fprintf(stderr,
+ "error: %s: string buffer is too small\n",
+ __FUNCTION__);
+ break;
+ }
strcat(path, "/");
strcat(path, dent->d_name);
* tool only makes sense for lustre filesystems. */
break;
case DT_DIR:
- ret = llapi_semantic_traverse(path, d, sem_init,
+ ret = llapi_semantic_traverse(path, size, d, sem_init,
sem_fini, data);
if (ret < 0)
goto out;
/* If a OST UUID is given, and some OST matches, check it here. */
if (decision != -1 && param->obdindex != OBD_NOT_FOUND) {
- /* Only those files should be accepted, which have a strip on
- * the specified OST. */
+ if (!S_ISREG(st->st_mode))
+ goto decided;
+
+ /* Only those files should be accepted, which have a
+ * stripe on the specified OST. */
if (!param->lmd->lmd_lmm.lmm_stripe_count) {
decision = -1;
} else {
if (!decision) {
int for_mds;
- for_mds = lustre_fs ? param->lmd->lmd_lmm.lmm_stripe_count : 0;
+ for_mds = lustre_fs ? (S_ISREG(st->st_mode) &&
+ param->lmd->lmd_lmm.lmm_stripe_count)
+ : 0;
decision = find_time_check(st, param, for_mds);
}
/* If file still fits the request, ask osd for updated info.
The regulat stat is almost of the same speed as some new
'glimpse-size-ioctl'. */
- if (!decision && param->lmd->lmd_lmm.lmm_stripe_count) {
+ if (!decision && param->lmd->lmd_lmm.lmm_stripe_count &&
+ S_ISREG(st->st_mode)) {
if (param->obdindex != OBD_NOT_FOUND) {
/* Check whether the obd is active or not, if it is
* not active, just print the object affected by this
printf("\n");
}
+decided:
/* Do not get down anymore? */
if (param->depth == param->maxdepth)
return 1;
int llapi_find(char *path, struct find_param *param)
{
- char buf[PATH_MAX + 1];
- int ret;
+ char *buf;
+ int ret, len = strlen(path);
+
+ if (len > PATH_MAX) {
+ fprintf(stderr, "%s: Path name '%s' is too long.\n",
+ __FUNCTION__, path);
+ return -EINVAL;
+ }
+
+ buf = (char *)malloc(PATH_MAX + 1);
+ if (!buf)
+ return -ENOMEM;
ret = common_param_init(param);
- if (ret)
+ if (ret) {
+ free(buf);
return ret;
+ }
param->depth = 0;
- strncpy(buf, path, strlen(path));
- buf[strlen(path)] = '\0';
- ret = llapi_semantic_traverse(buf, NULL, cb_find_init,
+ strncpy(buf, path, PATH_MAX + 1);
+ ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_find_init,
cb_common_fini, param);
find_param_fini(param);
+ free(buf);
return ret < 0 ? ret : 0;
}
int llapi_getstripe(char *path, struct find_param *param)
{
- int ret = 0;
+ char *buf;
+ int ret = 0, len = strlen(path);
+
+ if (len > PATH_MAX) {
+ fprintf(stderr, "%s: Path name '%s' is too long.\n",
+ __FUNCTION__, path);
+ return -EINVAL;
+ }
+
+ buf = (char *)malloc(PATH_MAX + 1);
+ if (!buf)
+ return -ENOMEM;
ret = common_param_init(param);
- if (ret)
+ if (ret) {
+ free(buf);
return ret;
+ }
param->depth = 0;
- ret = llapi_semantic_traverse(path, NULL, cb_getstripe,
+
+ strncpy(buf, path, PATH_MAX + 1);
+ ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_getstripe,
cb_common_fini, param);
find_param_fini(param);
+ free(buf);
return ret < 0 ? ret : 0;
}
int llapi_quotachown(char *path, int flag)
{
struct find_param param;
- int ret = 0;
+ char *buf;
+ int ret = 0, len = strlen(path);
+
+ if (len > PATH_MAX) {
+ fprintf(stderr, "%s: Path name '%s' is too long.\n",
+ __FUNCTION__, path);
+ return -EINVAL;
+ }
+
+ buf = (char *)malloc(PATH_MAX + 1);
+ if (!buf)
+ return -ENOMEM;
memset(¶m, 0, sizeof(param));
param.recursive = 1;
if (ret)
goto out;
- ret = llapi_semantic_traverse(path, NULL, cb_quotachown,
+ strncpy(buf, path, PATH_MAX + 1);
+ ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_quotachown,
NULL, ¶m);
out:
find_param_fini(¶m);
+ free(buf);
return ret;
}