*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
errmsg = strerror(errno);
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "error on ioctl "LPX64" for '%s' (%d): %s",
- (__u64)LL_IOC_LOV_SETSTRIPE, name, fd,
+ "error on ioctl %#jx for '%s' (%d): %s",
+ (uintmax_t)LL_IOC_LOV_SETSTRIPE, name, fd,
errmsg);
close(fd);
if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename)) {
char *errmsg = strerror(errno);
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "error on ioctl "LPX64" for '%s' (%d): %s",
- (__u64)LL_IOC_LMV_SETSTRIPE, filename,
+ "error on ioctl %#jx for '%s' (%d): %s",
+ (uintmax_t)LL_IOC_LMV_SETSTRIPE, filename,
fd, errmsg);
}
out:
*/
int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
{
- struct mntent mnt;
- char buf[PATH_MAX], mntdir[PATH_MAX];
- char *ptr;
- FILE *fp;
- int idx = 0, len = 0, mntlen, fd;
- int rc = -ENODEV;
+ struct mntent mnt;
+ char buf[PATH_MAX], mntdir[PATH_MAX];
+ char *ptr, *ptr_end;
+ FILE *fp;
+ int idx = 0, len = 0, mntlen, fd;
+ int rc = -ENODEV;
/* get the mount point */
- fp = setmntent(MOUNTED, "r");
- if (fp == NULL) {
- rc = -EIO;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "setmntent(%s) failed", MOUNTED);
- return rc;
- }
+ fp = setmntent(PROC_MOUNTS, "r");
+ if (fp == NULL) {
+ rc = -EIO;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "setmntent(%s) failed", PROC_MOUNTS);
+ return rc;
+ }
while (1) {
if (getmntent_r(fp, &mnt, buf, sizeof(buf)) == NULL)
break;
continue;
mntlen = strlen(mnt.mnt_dir);
- ptr = strrchr(mnt.mnt_fsname, '/');
+ ptr = strchr(mnt.mnt_fsname, '/');
+ while (ptr && *ptr == '/')
+ ptr++;
/* thanks to the call to llapi_is_lustre_mnt() above,
* we are sure that mnt.mnt_fsname contains ":/",
* so ptr should never be NULL */
if (ptr == NULL)
continue;
- ptr++;
+ ptr_end = ptr;
+ while (*ptr_end != '/' && *ptr_end != '\0')
+ ptr_end++;
- /* Check the fsname for a match, if given */
+ /* Check the fsname for a match, if given */
if (!(want & WANT_FSNAME) && fsname != NULL &&
- (strlen(fsname) > 0) && (strcmp(ptr, fsname) != 0))
+ (strlen(fsname) > 0) &&
+ (strncmp(ptr, fsname, ptr_end - ptr) != 0))
continue;
/* If the path isn't set return the first one we find */
- if (path == NULL || strlen(path) == 0) {
- strcpy(mntdir, mnt.mnt_dir);
- if ((want & WANT_FSNAME) && fsname != NULL)
- strcpy(fsname, ptr);
- rc = 0;
- break;
- /* Otherwise find the longest matching path */
- } else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
- (strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
- strcpy(mntdir, mnt.mnt_dir);
- len = mntlen;
- if ((want & WANT_FSNAME) && fsname != NULL)
- strcpy(fsname, ptr);
- rc = 0;
- }
- }
- endmntent(fp);
-
- /* Found it */
- if (rc == 0) {
- if ((want & WANT_PATH) && path != NULL)
- strcpy(path, mntdir);
- if (want & WANT_FD) {
- fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
- if (fd < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "error opening '%s'", mntdir);
+ if (path == NULL || strlen(path) == 0) {
+ strncpy(mntdir, mnt.mnt_dir, strlen(mnt.mnt_dir));
+ mntdir[strlen(mnt.mnt_dir)] = '\0';
+ if ((want & WANT_FSNAME) && fsname != NULL) {
+ strncpy(fsname, ptr, ptr_end - ptr);
+ fsname[ptr_end - ptr] = '\0';
+ }
+ rc = 0;
+ break;
+ /* Otherwise find the longest matching path */
+ } else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
+ (strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
+ strncpy(mntdir, mnt.mnt_dir, strlen(mnt.mnt_dir));
+ mntdir[strlen(mnt.mnt_dir)] = '\0';
+ len = mntlen;
+ if ((want & WANT_FSNAME) && fsname != NULL) {
+ strncpy(fsname, ptr, ptr_end - ptr);
+ fsname[ptr_end - ptr] = '\0';
+ }
+ rc = 0;
+ }
+ }
+ endmntent(fp);
- } else {
- *outfd = fd;
- }
- }
- } else if (want & WANT_ERROR)
- llapi_err_noerrno(LLAPI_MSG_ERROR,
- "can't find fs root for '%s': %d",
- (want & WANT_PATH) ? fsname : path, rc);
- return rc;
+ /* Found it */
+ if (rc == 0) {
+ if ((want & WANT_PATH) && path != NULL) {
+ strncpy(path, mntdir, strlen(mntdir));
+ path[strlen(mntdir)] = '\0';
+ }
+ if (want & WANT_FD) {
+ fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
+ if (fd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error opening '%s'", mntdir);
+
+ } else {
+ *outfd = fd;
+ }
+ }
+ } else if (want & WANT_ERROR)
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "can't find fs root for '%s': %d",
+ (want & WANT_PATH) ? fsname : path, rc);
+ return rc;
}
/*
int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid)
{
- int fd, rc;
+ int fd, rc;
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
- return rc;
- }
+ fd = open(path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
+ return rc;
+ }
- rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
+ rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
- close(fd);
- return rc;
+ close(fd);
+ return rc;
}
int llapi_file_get_lmv_uuid(const char *path, struct obd_uuid *lov_uuid)
{
int fd, rc;
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
uuids_temp = realloc(uuids, obdcount *
sizeof(struct obd_uuid));
if (uuids_temp != NULL) {
- free(uuids);
uuids = uuids_temp;
goto retry_get_uuids;
}
}
static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
- struct lov_user_ost_data_v1 *objects,
- int is_dir, int verbose, int depth,
- int raw, char *pool_name)
+ struct lov_user_ost_data_v1 *objects,
+ int is_dir, int verbose, int depth,
+ int raw, char *pool_name)
{
- char *prefix = is_dir ? "" : "lmm_";
+ char *prefix = is_dir ? "" : "lmm_";
char *separator = "";
- int rc;
+ int rc;
if (is_dir && lmm_oi_seq(&lum->lmm_oi) == FID_SEQ_LOV_DEFAULT) {
lmm_oi_set_seq(&lum->lmm_oi, 0);
llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
}
- if (depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
- llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
+ if (depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
+ llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
if ((verbose & VERBOSE_DETAIL) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic: 0x%08X\n",
lum->lmm_magic);
- llapi_printf(LLAPI_MSG_NORMAL, "lmm_seq: "LPX64"\n",
- lmm_oi_seq(&lum->lmm_oi));
- llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: "LPX64"\n",
- lmm_oi_id(&lum->lmm_oi));
+ llapi_printf(LLAPI_MSG_NORMAL, "lmm_seq: %#jx\n",
+ (uintmax_t)lmm_oi_seq(&lum->lmm_oi));
+ llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: %#jx\n",
+ (uintmax_t)lmm_oi_id(&lum->lmm_oi));
+ }
+ if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) {
+ if (verbose & ~VERBOSE_DFID)
+ llapi_printf(LLAPI_MSG_NORMAL, "lmm_fid: ");
+ /* This needs a bit of hand-holding since old 1.x lmm_oi
+ * have { oi.oi_id = mds_inum, oi.oi_seq = 0 } and 2.x lmm_oi
+ * have { oi.oi_id = mds_oid, oi.oi_seq = mds_seq } instead of
+ * a real FID. Ideally the 2.x code would have stored this
+ * like a FID with { oi_id = mds_seq, oi_seq = mds_oid } so the
+ * ostid union lu_fid { f_seq = mds_seq, f_oid = mds_oid }
+ * worked properly (especially since IGIF FIDs use mds_inum as
+ * the FID SEQ), but unfortunately that didn't happen.
+ *
+ * Print it to look like an IGIF FID, even though the fields
+ * are reversed on disk, so that it makes sense to userspace.
+ *
+ * Don't use ostid_id() and ostid_seq(), since they assume the
+ * oi_fid fields are in the right order. This is why there are
+ * separate lmm_oi_seq() and lmm_oi_id() routines for this.
+ *
+ * For newer layout types hopefully this will be a real FID. */
+ llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
+ lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ lmm_oi_id(&lum->lmm_oi) :
+ lmm_oi_seq(&lum->lmm_oi),
+ lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ 0 : (__u32)lmm_oi_id(&lum->lmm_oi),
+ (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32));
}
- if (verbose & VERBOSE_COUNT) {
- if (verbose & ~VERBOSE_COUNT)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
- prefix);
- if (is_dir) {
- if (!raw && lum->lmm_stripe_count == 0) {
- unsigned int scount;
- rc = sattr_cache_get_defaults(NULL, path,
- &scount, NULL,
- NULL);
- if (rc == 0)
+ if (verbose & VERBOSE_COUNT) {
+ if (verbose & ~VERBOSE_COUNT)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
+ prefix);
+ if (is_dir) {
+ if (!raw && lum->lmm_stripe_count == 0) {
+ unsigned int scount;
+ rc = sattr_cache_get_defaults(NULL, path,
+ &scount, NULL,
+ NULL);
+ if (rc == 0)
llapi_printf(LLAPI_MSG_NORMAL, "%d",
scount);
- else
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Cannot determine default"
- " stripe count.");
- } else {
+ else
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Cannot determine default"
+ " stripe count.");
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%d",
- lum->lmm_stripe_count ==
- (typeof(lum->lmm_stripe_count))(-1)
+ lum->lmm_stripe_count ==
+ (typeof(lum->lmm_stripe_count))(-1)
? -1 : lum->lmm_stripe_count);
- }
- } else {
+ }
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%hd",
(__s16)lum->lmm_stripe_count);
- }
+ }
separator = is_dir ? " " : "\n";
- }
+ }
- if (verbose & VERBOSE_SIZE) {
+ if (verbose & VERBOSE_SIZE) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_SIZE)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
- prefix);
- if (is_dir && !raw && lum->lmm_stripe_size == 0) {
- unsigned int ssize;
- rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
- NULL);
- if (rc == 0)
+ if (verbose & ~VERBOSE_SIZE)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
+ prefix);
+ if (is_dir && !raw && lum->lmm_stripe_size == 0) {
+ unsigned int ssize;
+ rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
+ NULL);
+ if (rc == 0)
llapi_printf(LLAPI_MSG_NORMAL, "%u", ssize);
- else
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Cannot determine default"
- " stripe size.");
- } else {
+ else
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Cannot determine default"
+ " stripe size.");
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%u",
lum->lmm_stripe_size);
- }
+ }
separator = is_dir ? " " : "\n";
- }
+ }
if ((verbose & VERBOSE_LAYOUT) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
separator = "\n";
}
- if ((verbose & VERBOSE_GENERATION) && !is_dir) {
+ if ((verbose & VERBOSE_GENERATION) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_GENERATION)
- llapi_printf(LLAPI_MSG_NORMAL, "%slayout_gen: ",
- prefix);
+ if (verbose & ~VERBOSE_GENERATION)
+ llapi_printf(LLAPI_MSG_NORMAL, "%slayout_gen: ",
+ prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%u",
(int)lum->lmm_layout_gen);
separator = "\n";
- }
+ }
- if (verbose & VERBOSE_OFFSET) {
+ if (verbose & VERBOSE_OFFSET) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_OFFSET)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
- prefix);
- if (is_dir)
+ if (verbose & ~VERBOSE_OFFSET)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
+ prefix);
+ if (is_dir)
llapi_printf(LLAPI_MSG_NORMAL, "%d",
- lum->lmm_stripe_offset ==
- (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
+ lum->lmm_stripe_offset ==
+ (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
lum->lmm_stripe_offset);
- else
+ else
llapi_printf(LLAPI_MSG_NORMAL, "%u",
objects[0].l_ost_idx);
separator = is_dir ? " " : "\n";
- }
+ }
- if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
+ if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_POOL)
- llapi_printf(LLAPI_MSG_NORMAL, "%spool: ",
- prefix);
+ if (verbose & ~VERBOSE_POOL)
+ llapi_printf(LLAPI_MSG_NORMAL, "%spool: ",
+ prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name);
- }
+ }
- if (!is_dir || (is_dir && (verbose != VERBOSE_OBJID)))
- llapi_printf(LLAPI_MSG_NORMAL, "\n");
+ if (!is_dir || (is_dir && (verbose != VERBOSE_OBJID)))
+ llapi_printf(LLAPI_MSG_NORMAL, "\n");
}
void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
int llapi_file_get_stripe(const char *path, struct lov_user_md *lum)
{
- const char *fname;
- char *dname;
- 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 = (char *)path;
- } else {
- dname = (char *)malloc(fname - path + 1);
- if (dname == NULL)
- return -ENOMEM;
- strncpy(dname, path, fname - path);
- dname[fname - path] = '\0';
- fname++;
- }
+ const char *fname;
+ char *dname;
+ int fd, rc = 0;
- fd = open(dname, O_RDONLY);
- if (fd == -1) {
- rc = -errno;
- free(dname);
- return rc;
- }
+ fname = strrchr(path, '/');
- strcpy((char *)lum, fname);
- if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
- rc = -errno;
+ /* It should be a file (or other non-directory) */
+ if (fname == NULL) {
+ dname = (char *)malloc(2);
+ if (dname == NULL)
+ return -ENOMEM;
+ strcpy(dname, ".");
+ fname = (char *)path;
+ } else {
+ dname = (char *)malloc(fname - path + 1);
+ if (dname == NULL)
+ return -ENOMEM;
+ strncpy(dname, path, fname - path);
+ dname[fname - path] = '\0';
+ fname++;
+ }
- if (close(fd) == -1 && rc == 0)
- rc = -errno;
+ fd = open(dname, O_RDONLY | O_NONBLOCK);
+ if (fd == -1) {
+ rc = -errno;
+ free(dname);
+ return rc;
+ }
- free(dname);
- return rc;
+ strcpy((char *)lum, fname);
+ if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
+ rc = -errno;
+
+ if (close(fd) == -1 && rc == 0)
+ rc = -errno;
+
+ free(dname);
+ return rc;
}
int llapi_file_lookup(int dirfd, const char *name)
int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
{
- DIR *root;
- int rc;
+ char fsname[PATH_MAX + 1];
+ DIR *root;
+ int rc;
+
+ rc = llapi_search_fsname(mnt, fsname);
+ if (rc) {
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "'%s' isn't on Lustre filesystem", mnt);
+ return rc;
+ }
root = opendir(mnt);
if (!root) {
return rc;
}
-#include <pwd.h>
-#include <grp.h>
-#include <mntent.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <ctype.h>
-
-static int rmtacl_notify(int ops)
-{
- FILE *fp;
- struct mntent *mnt;
- int found = 0, fd = 0, rc = 0;
-
- fp = setmntent(MOUNTED, "r");
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "error setmntent(%s)", MOUNTED);
- return rc;
- }
-
- while (1) {
- mnt = getmntent(fp);
- if (!mnt)
- break;
-
- if (!llapi_is_lustre_mnt(mnt))
- continue;
-
- fd = open(mnt->mnt_dir, O_RDONLY | O_DIRECTORY);
- if (fd < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Can't open '%s'", mnt->mnt_dir);
- goto out;
- }
-
- rc = ioctl(fd, LL_IOC_RMTACL, ops);
- close(fd);
- if (rc < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "ioctl RMTACL on '%s' err %d",
- mnt->mnt_dir, rc);
- goto out;
- }
-
- found++;
- }
-
-out:
- endmntent(fp);
- return ((rc != 0) ? rc : found);
-}
-
-static char *next_token(char *p, int div)
-{
- if (p == NULL)
- return NULL;
-
- if (div)
- while (*p && *p != ':' && !isspace(*p))
- p++;
- else
- while (*p == ':' || isspace(*p))
- p++;
-
- return *p ? p : NULL;
-}
-
-static int rmtacl_name2id(char *name, int is_user)
-{
- if (is_user) {
- struct passwd *pw;
-
- pw = getpwnam(name);
- if (pw == NULL)
- return INVALID_ID;
- else
- return (int)(pw->pw_uid);
- } else {
- struct group *gr;
-
- gr = getgrnam(name);
- if (gr == NULL)
- return INVALID_ID;
- else
- return (int)(gr->gr_gid);
- }
-}
-
-static int isodigit(int c)
-{
- return (c >= '0' && c <= '7') ? 1 : 0;
-}
-
-/*
- * Whether the name is just digits string (uid/gid) already or not.
- * Return value:
- * 1: str is id
- * 0: str is not id
- */
-static int str_is_id(char *str)
-{
- if (str == NULL)
- return 0;
-
- if (*str == '0') {
- str++;
- if (*str == 'x' || *str == 'X') { /* for Hex. */
- if (!isxdigit(*(++str)))
- return 0;
-
- while (isxdigit(*(++str)));
- } else if (isodigit(*str)) { /* for Oct. */
- while (isodigit(*(++str)));
- }
- } else if (isdigit(*str)) { /* for Dec. */
- while (isdigit(*(++str)));
- }
-
- return (*str == 0) ? 1 : 0;
-}
-
-typedef struct {
- char *name;
- int length;
- int is_user;
- int next_token;
-} rmtacl_name_t;
-
-#define RMTACL_OPTNAME(name) name, sizeof(name) - 1
-
-static rmtacl_name_t rmtacl_namelist[] = {
- { RMTACL_OPTNAME("user:"), 1, 0 },
- { RMTACL_OPTNAME("group:"), 0, 0 },
- { RMTACL_OPTNAME("default:user:"), 1, 0 },
- { RMTACL_OPTNAME("default:group:"), 0, 0 },
- /* for --tabular option */
- { RMTACL_OPTNAME("user"), 1, 1 },
- { RMTACL_OPTNAME("group"), 0, 1 },
- { 0 }
-};
-
-static int rgetfacl_output(char *str)
-{
- char *start = NULL, *end = NULL;
- int is_user = 0, n, id;
- char c;
- rmtacl_name_t *rn;
-
- if (str == NULL)
- return -1;
-
- for (rn = rmtacl_namelist; rn->name; rn++) {
- if(strncmp(str, rn->name, rn->length) == 0) {
- if (!rn->next_token)
- start = str + rn->length;
- else
- start = next_token(str + rn->length, 0);
- is_user = rn->is_user;
- break;
- }
- }
-
- end = next_token(start, 1);
- if (end == NULL || start == end) {
- n = printf("%s", str);
- return n;
- }
-
- c = *end;
- *end = 0;
- id = rmtacl_name2id(start, is_user);
- if (id == INVALID_ID) {
- if (str_is_id(start)) {
- *end = c;
- n = printf("%s", str);
- } else
- return -1;
- } else if ((id == NOBODY_UID && is_user) ||
- (id == NOBODY_GID && !is_user)) {
- *end = c;
- n = printf("%s", str);
- } else {
- *end = c;
- *start = 0;
- n = printf("%s%d%s", str, id, end);
- }
- return n;
-}
-
-static int child_status(int status)
-{
- return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
-}
-
-static int do_rmtacl(int argc, char *argv[], int ops, int (output_func)(char *))
-{
- pid_t pid = 0;
- int fd[2], status, rc;
- FILE *fp;
- char buf[PIPE_BUF];
-
- if (output_func) {
- if (pipe(fd) < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "Can't create pipe");
- return rc;
- }
-
- pid = fork();
- if (pid < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "Can't fork");
- close(fd[0]);
- close(fd[1]);
- return rc;
- } else if (!pid) {
- /* child process redirects its output. */
- close(fd[0]);
- close(1);
- if (dup2(fd[1], 1) < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Can't dup2 %d", fd[1]);
- close(fd[1]);
- return rc;
- }
- } else {
- close(fd[1]);
- }
- }
-
- if (!pid) {
- status = rmtacl_notify(ops);
- if (status < 0)
- return -errno;
-
- exit(execvp(argv[0], argv));
- }
-
- /* the following is parent process */
- fp = fdopen(fd[0], "r");
- if (fp == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "fdopen %d failed", fd[0]);
- kill(pid, SIGKILL);
- close(fd[0]);
- return rc;
- }
-
- while (fgets(buf, PIPE_BUF, fp) != NULL) {
- if (output_func(buf) < 0)
- fprintf(stderr, "WARNING: unexpected error!\n[%s]\n",
- buf);
- }
- fclose(fp);
- close(fd[0]);
-
- if (waitpid(pid, &status, 0) < 0) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "waitpid %d failed", pid);
- return rc;
- }
-
- return child_status(status);
-}
-
-int llapi_lsetfacl(int argc, char *argv[])
-{
- return do_rmtacl(argc, argv, RMT_LSETFACL, NULL);
-}
-
-int llapi_lgetfacl(int argc, char *argv[])
-{
- return do_rmtacl(argc, argv, RMT_LGETFACL, NULL);
-}
-
-int llapi_rsetfacl(int argc, char *argv[])
-{
- return do_rmtacl(argc, argv, RMT_RSETFACL, NULL);
-}
-
-int llapi_rgetfacl(int argc, char *argv[])
-{
- return do_rmtacl(argc, argv, RMT_RGETFACL, rgetfacl_output);
-}
-
-int llapi_cp(int argc, char *argv[])
-{
- int rc;
-
- rc = rmtacl_notify(RMT_RSETFACL);
- if (rc < 0)
- return rc;
-
- exit(execvp(argv[0], argv));
-}
-
-int llapi_ls(int argc, char *argv[])
-{
- int rc;
-
- rc = rmtacl_notify(RMT_LGETFACL);
- if (rc < 0)
- return rc;
-
- exit(execvp(argv[0], argv));
-}
-
/* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed.
* format must have %s%s, buf must be > 16
* Eg: if name = "lustre-MDT0000", "lustre", or "lustre-MDT0000_UUID"
rc = -errno;
else
rc = 0;
- if (rc && want_error)
- llapi_error(LLAPI_MSG_ERROR, rc, "ioctl %d err %d", opc, rc);
-
close(fd);
return rc;
}
int llapi_fid2path(const char *device, const char *fidstr, char *buf,
int buflen, long long *recno, int *linkno)
{
+ const char *fidstr_orig = fidstr;
struct lu_fid fid;
struct getinfo_fid2path *gf;
int rc;
sscanf(fidstr, SFID, RFID(&fid));
if (!fid_is_sane(&fid)) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "bad FID format [%s], should be [seq:oid:ver]"
- " (e.g. "DFID")\n", fidstr,
+ "bad FID format '%s', should be [seq:oid:ver]"
+ " (e.g. "DFID")\n", fidstr_orig,
(unsigned long long)FID_SEQ_NORMAL, 2, 0);
return -EINVAL;
}
gf = malloc(sizeof(*gf) + buflen);
if (gf == NULL)
return -ENOMEM;
+
gf->gf_fid = fid;
gf->gf_recno = *recno;
gf->gf_linkno = *linkno;
/* Take path or fsname */
rc = root_ioctl(device, OBD_IOC_FID2PATH, gf, NULL, 0);
- if (rc) {
- if (rc != -ENOENT)
- llapi_error(LLAPI_MSG_ERROR, rc, "ioctl err %d", rc);
- } else {
- memcpy(buf, gf->gf_path, gf->gf_pathlen);
- if (buf[0] == '\0') { /* ROOT path */
- buf[0] = '/';
- buf[1] = '\0';
- }
- *recno = gf->gf_recno;
- *linkno = gf->gf_linkno;
- }
+ if (rc)
+ goto out_free;
- free(gf);
- return rc;
+ memcpy(buf, gf->gf_u.gf_path, gf->gf_pathlen);
+ if (buf[0] == '\0') { /* ROOT path */
+ buf[0] = '/';
+ buf[1] = '\0';
+ }
+ *recno = gf->gf_recno;
+ *linkno = gf->gf_linkno;
+
+out_free:
+ free(gf);
+ return rc;
}
static int fid_from_lma(const char *path, const int fd, lustre_fid *fid)
return rc;
}
-int llapi_get_version(char *buffer, int buffer_size,
- char **version)
-{
- int rc;
- int fd;
- struct obd_ioctl_data *data = (struct obd_ioctl_data *)buffer;
-
- fd = open(OBD_DEV_PATH, O_RDONLY);
- if (fd == -1)
- return -errno;
-
- memset(buffer, 0, buffer_size);
- data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_inllen1 = buffer_size - cfs_size_round(sizeof(*data));
- data->ioc_inlbuf1 = buffer + cfs_size_round(sizeof(*data));
- data->ioc_len = obd_ioctl_packlen(data);
-
- rc = ioctl(fd, OBD_GET_VERSION, buffer);
- if (rc == -1) {
- rc = -errno;
- close(fd);
- return rc;
- }
- close(fd);
- *version = data->ioc_bulk;
- return 0;
-}
-
/**
* Get a 64-bit value representing the version of file data pointed by fd.
*