#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
+#ifdef HAVE_LINUX_TYPES_H
#include <linux/types.h>
+#else
+#include "types.h"
+#endif
+#ifdef HAVE_LINUX_UNISTD_H
#include <linux/unistd.h>
-
+#else
+#include <unistd.h>
+#endif
#include <liblustre.h>
#include <linux/obd.h>
#include <linux/lustre_lib.h>
{
struct lov_user_md lum = { 0 };
int fd, rc = 0;
+ int isdir = 0;
/* Initialize IOCTL striping pattern structure */
lum.lmm_magic = LOV_USER_MAGIC;
lum.lmm_stripe_offset = stripe_offset;
fd = open(name, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
- if (errno == EISDIR)
+ if (errno == EISDIR) {
fd = open(name, O_DIRECTORY | O_RDONLY);
+ isdir++;
+ }
if (fd < 0) {
err_msg("unable to open '%s'",name);
return rc;
}
+ /* setting stripe pattern 0 -1 0 to a dir means to delete it */
+ if (isdir) {
+ if (stripe_size == 0 && stripe_count == 0 &&
+ stripe_offset == -1)
+ lum.lmm_stripe_size = -1;
+ } else {
+ if (stripe_size == -1) {
+ err_msg("deleting file stripe info is not allowed\n");
+ rc = -EPERM;
+ goto out;
+ }
+ }
+
if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum)) {
char *errmsg = "stripe already set";
if (errno != EEXIST && errno != EALREADY)
name, fd, errmsg);
rc = -errno;
}
+out:
if (close(fd) < 0) {
err_msg("error on close for '%s' (%d)", name, fd);
if (rc == 0)
out:
free(buf);
- return 0;
+ return rc;
}
static int setup_obd_uuids(DIR *dir, char *dname, struct find_param *param)
char rawbuf[OBD_MAX_IOCTL_BUFFER];
char *bufl = rawbuf;
char *bufp = buf;
- int max = sizeof(rawbuf);
- struct obd_ioctl_data datal;
+ struct obd_ioctl_data datal = { 0, };
struct obd_statfs osfs_buffer;
while(bufp[0] == ' ')
datal.ioc_inlbuf1 = obd_name;
datal.ioc_inllen1 = strlen(obd_name) + 1;
- obd_ioctl_pack(&datal,&bufl,max);
+ rc = obd_ioctl_pack(&datal, &bufl, OBD_MAX_IOCTL_BUFFER);
+ if (rc) {
+ fprintf(stderr, "internal buffer error packing\n");
+ break;
+ }
rc = ioctl(dirfd(opendir(dir)), OBD_IOC_PING,
bufl);