1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/liblustreapi.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 * Author: Robert Read <rread@clusterfs.com>
52 #include <sys/ioctl.h>
59 #include <sys/types.h>
60 #include <sys/syscall.h>
63 #ifdef HAVE_LINUX_UNISTD_H
64 #include <linux/unistd.h>
70 #include <liblustre.h>
71 #include <lnet/lnetctl.h>
73 #include <lustre_lib.h>
75 #include <lustre/liblustreapi.h>
77 static unsigned llapi_dir_filetype_table[] = {
86 #if defined(DT_DOOR) && defined(S_IFDOOR)
91 #if defined(DT_DOOR) && defined(S_IFDOOR)
92 static const int DT_MAX = DT_DOOR;
94 static const int DT_MAX = DT_SOCK;
97 static unsigned llapi_filetype_dir_table[] = {
106 #if defined(DT_DOOR) && defined(S_IFDOOR)
111 #if defined(DT_DOOR) && defined(S_IFDOOR)
112 static const int S_IFMAX = DT_DOOR;
114 static const int S_IFMAX = DT_SOCK;
117 /* liblustreapi message level */
118 static int llapi_msg_level = LLAPI_MSG_MAX;
120 void llapi_msg_set_level(int level)
122 /* ensure level is in the good range */
123 if (level < LLAPI_MSG_OFF)
124 llapi_msg_level = LLAPI_MSG_OFF;
125 else if (level > LLAPI_MSG_MAX)
126 llapi_msg_level = LLAPI_MSG_MAX;
128 llapi_msg_level = level;
131 void llapi_err(int level, char *fmt, ...)
134 int tmp_errno = abs(errno);
136 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
140 vfprintf(stderr, fmt, args);
143 if (level & LLAPI_MSG_NO_ERRNO)
144 fprintf(stderr, "\n");
146 fprintf(stderr, ": %s (%d)\n", strerror(tmp_errno), tmp_errno);
149 #define llapi_err_noerrno(level, fmt, a...) \
150 llapi_err((level) | LLAPI_MSG_NO_ERRNO, fmt, ## a)
152 void llapi_printf(int level, char *fmt, ...)
156 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
160 vfprintf(stdout, fmt, args);
165 * size_units is unchanged if no specifier used
167 int parse_size(char *optarg, unsigned long long *size,
168 unsigned long long *size_units, int bytes_spec)
172 *size = strtoull(optarg, &end, 0);
175 if ((*end == 'b') && *(end+1) == '\0' &&
176 (*size & (~0ULL << (64 - 9))) == 0 &&
179 *size_units = 1 << 9;
180 } else if ((*end == 'b') && *(end+1) == '\0' &&
183 } else if ((*end == 'k' || *end == 'K') &&
184 *(end+1) == '\0' && (*size &
185 (~0ULL << (64 - 10))) == 0) {
187 *size_units = 1 << 10;
188 } else if ((*end == 'm' || *end == 'M') &&
189 *(end+1) == '\0' && (*size &
190 (~0ULL << (64 - 20))) == 0) {
192 *size_units = 1 << 20;
193 } else if ((*end == 'g' || *end == 'G') &&
194 *(end+1) == '\0' && (*size &
195 (~0ULL << (64 - 30))) == 0) {
197 *size_units = 1 << 30;
198 } else if ((*end == 't' || *end == 'T') &&
199 *(end+1) == '\0' && (*size &
200 (~0ULL << (64 - 40))) == 0) {
202 *size_units = 1ULL << 40;
203 } else if ((*end == 'p' || *end == 'P') &&
204 *(end+1) == '\0' && (*size &
205 (~0ULL << (64 - 50))) == 0) {
207 *size_units = 1ULL << 50;
208 } else if ((*end == 'e' || *end == 'E') &&
209 *(end+1) == '\0' && (*size &
210 (~0ULL << (64 - 60))) == 0) {
212 *size_units = 1ULL << 60;
221 int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
222 int stripe_count, int stripe_pattern)
226 /* 64 KB is the largest common page size I'm aware of (on ia64), but
227 * check the local page size just in case. */
228 page_size = LOV_MIN_STRIPE_SIZE;
229 if (getpagesize() > page_size) {
230 page_size = getpagesize();
231 llapi_err_noerrno(LLAPI_MSG_WARN,
232 "warning: your page size (%u) is "
233 "larger than expected (%u)", page_size,
234 LOV_MIN_STRIPE_SIZE);
236 if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) {
237 llapi_err(LLAPI_MSG_ERROR, "error: bad stripe_size %lu, "
238 "must be an even multiple of %d bytes",
239 stripe_size, page_size);
242 if (stripe_offset < -1 || stripe_offset > MAX_OBD_DEVICES) {
244 llapi_err(LLAPI_MSG_ERROR, "error: bad stripe offset %d",
248 if (stripe_count < -1 || stripe_count > LOV_MAX_STRIPE_COUNT) {
250 llapi_err(LLAPI_MSG_ERROR, "error: bad stripe count %d",
254 if (stripe_size >= (1ULL << 32)){
256 llapi_err(LLAPI_MSG_ERROR, "warning: stripe size larger than 4G"
257 " is not currently supported and would wrap");
263 static int poolpath(char *fsname, char *pathname, char *pool_pathname);
265 int llapi_file_open_pool(const char *name, int flags, int mode,
266 unsigned long long stripe_size, int stripe_offset,
267 int stripe_count, int stripe_pattern, char *pool_name)
269 struct lov_user_md_v3 lum = { 0 };
272 char fsname[MAX_OBD_NAME + 1], *ptr;
274 fd = open(name, flags | O_LOV_DELAY_CREATE, mode);
275 if (fd < 0 && errno == EISDIR) {
276 fd = open(name, O_DIRECTORY | O_RDONLY);
282 llapi_err(LLAPI_MSG_ERROR, "unable to open '%s'", name);
286 if ((rc = llapi_stripe_limit_check(stripe_size, stripe_offset,
287 stripe_count, stripe_pattern)) != 0){
292 /* Initialize IOCTL striping pattern structure */
293 lum.lmm_magic = LOV_USER_MAGIC_V3;
294 lum.lmm_pattern = stripe_pattern;
295 lum.lmm_stripe_size = stripe_size;
296 lum.lmm_stripe_count = stripe_count;
297 lum.lmm_stripe_offset = stripe_offset;
299 /* in case user give the full pool name <fsname>.<poolname>, skip
301 if (pool_name != NULL) {
302 ptr = strchr(pool_name, '.');
304 strncpy(fsname, pool_name, ptr - pool_name);
306 /* if fsname matches a filesystem skip it
307 * if not keep the poolname as is */
308 if (poolpath(fsname, NULL, NULL) == 0)
311 strncpy(lum.lmm_pool_name, pool_name, LOV_MAXPOOLNAME);
313 /* If no pool is specified at all, use V1 request */
314 lum.lmm_magic = LOV_USER_MAGIC_V1;
317 if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum)) {
318 char *errmsg = "stripe already set";
320 if (errno != EEXIST && errno != EALREADY)
321 errmsg = strerror(errno);
323 llapi_err_noerrno(LLAPI_MSG_ERROR,
324 "error on ioctl "LPX64" for '%s' (%d): %s",
325 (__u64)LL_IOC_LOV_SETSTRIPE, name, fd,errmsg);
336 int llapi_file_open(const char *name, int flags, int mode,
337 unsigned long long stripe_size, int stripe_offset,
338 int stripe_count, int stripe_pattern)
340 return llapi_file_open_pool(name, flags, mode, stripe_size,
341 stripe_offset, stripe_count,
342 stripe_pattern, NULL);
345 int llapi_file_create(const char *name, unsigned long long stripe_size,
346 int stripe_offset, int stripe_count, int stripe_pattern)
350 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
351 stripe_offset, stripe_count, stripe_pattern,
360 int llapi_file_create_pool(const char *name, unsigned long long stripe_size,
361 int stripe_offset, int stripe_count,
362 int stripe_pattern, char *pool_name)
366 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
367 stripe_offset, stripe_count, stripe_pattern,
377 * Find the fsname, the full path, and/or an open fd.
378 * Either the fsname or path must not be NULL
380 #define WANT_PATH 0x1
381 #define WANT_FSNAME 0x2
383 static int get_root_path(int want, char *fsname, int *outfd, char *path)
392 /* get the mount point */
393 fp = setmntent(MOUNTED, "r");
395 llapi_err(LLAPI_MSG_ERROR,
396 "setmntent(%s) failed: %s:", MOUNTED,
401 if (getmntent_r(fp, &mnt, buf, sizeof(buf)) == NULL)
404 if (!llapi_is_lustre_mnt(&mnt))
407 ptr = strrchr(mnt.mnt_fsname, '/');
414 /* If path was specified and matches, store the fsname */
415 if ((want & WANT_FSNAME) && (strcmp(mnt.mnt_dir, path) == 0))
417 /* Else check the fsname for a match */
418 else if (strcmp(ptr, fsname) != 0)
423 if (want & WANT_PATH)
424 strcpy(path, mnt.mnt_dir);
425 if (want & WANT_FD) {
426 fd = open(mnt.mnt_dir,
427 O_RDONLY | O_DIRECTORY | O_NONBLOCK);
439 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
440 "can't find fs root for '%s': %d",
441 (want & WANT_PATH) ? fsname : path, rc);
445 int llapi_search_fsname(const char *pathname, char *fsname)
447 return get_root_path(WANT_FSNAME, fsname, NULL, (char *)pathname);
450 /* return the first file matching this pattern */
451 static int first_match(char *pattern, char *buffer)
455 if (glob(pattern, GLOB_BRACE, NULL, &glob_info))
458 if (glob_info.gl_pathc < 1) {
459 globfree(&glob_info);
463 strcpy(buffer, glob_info.gl_pathv[0]);
465 globfree(&glob_info);
470 * find the pool directory path under /proc
471 * (can be also used to test if a fsname is known)
473 static int poolpath(char *fsname, char *pathname, char *pool_pathname)
476 char pattern[PATH_MAX + 1];
477 char buffer[PATH_MAX];
479 if (fsname == NULL) {
480 rc = get_root_path(WANT_FSNAME, buffer, NULL, pathname);
484 strcpy(pathname, fsname);
487 snprintf(pattern, PATH_MAX, "/proc/fs/lustre/lov/%s-*/pools", fsname);
488 rc = first_match(pattern, buffer);
492 /* in fsname test mode, pool_pathname is NULL */
493 if (pool_pathname != NULL)
494 strcpy(pool_pathname, buffer);
500 * Get the list of pool members.
501 * \param poolname string of format <fsname>.<poolname>
502 * \param members caller-allocated array of char*
503 * \param list_size size of the members array
504 * \param buffer caller-allocated buffer for storing OST names
505 * \param buffer_size size of the buffer
507 * \return number of members retrieved for this pool
508 * \retval -error failure
510 int llapi_get_poolmembers(const char *poolname, char **members,
511 int list_size, char *buffer, int buffer_size)
513 char fsname[PATH_MAX + 1];
515 char pathname[PATH_MAX + 1];
516 char path[PATH_MAX + 1];
523 /* name is FSNAME.POOLNAME */
524 if (strlen(poolname) > PATH_MAX)
526 strcpy(fsname, poolname);
527 pool = strchr(fsname, '.');
534 rc = poolpath(fsname, NULL, pathname);
537 llapi_err(LLAPI_MSG_ERROR, "Lustre filesystem '%s' not found",
542 llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
543 sprintf(path, "%s/%s", pathname, pool);
544 if ((fd = fopen(path, "r")) == NULL) {
545 llapi_err(LLAPI_MSG_ERROR, "Cannot open %s", path);
550 while (fgets(buf, sizeof(buf), fd) != NULL) {
551 if (nb_entries >= list_size) {
556 if ((tmp = strchr(buf, '\n')) != NULL)
558 if (used + strlen(buf) + 1 > buffer_size) {
563 strcpy(buffer + used, buf);
564 members[nb_entries] = buffer + used;
565 used += strlen(buf) + 1;
575 * Get the list of pools in a filesystem.
576 * \param name filesystem name or path
577 * \param poollist caller-allocated array of char*
578 * \param list_size size of the poollist array
579 * \param buffer caller-allocated buffer for storing pool names
580 * \param buffer_size size of the buffer
582 * \return number of pools retrieved for this filesystem
583 * \retval -error failure
585 int llapi_get_poollist(const char *name, char **poollist, int list_size,
586 char *buffer, int buffer_size)
588 char fsname[PATH_MAX + 1], rname[PATH_MAX + 1], pathname[PATH_MAX + 1];
592 struct dirent *cookie = NULL;
594 unsigned int nb_entries = 0;
595 unsigned int used = 0;
598 /* initilize output array */
599 for (i = 0; i < list_size; i++)
602 /* is name a pathname ? */
603 ptr = strchr(name, '/');
605 /* only absolute pathname is supported */
608 if (!realpath(name, rname)) {
610 llapi_err(LLAPI_MSG_ERROR, "invalid path '%s'", name);
614 rc = poolpath(NULL, rname, pathname);
617 llapi_err(LLAPI_MSG_ERROR, "'%s' is not"
618 " a Lustre filesystem", name);
621 strcpy(fsname, rname);
624 strcpy(fsname, name);
625 rc = poolpath(fsname, NULL, pathname);
629 llapi_err(LLAPI_MSG_ERROR, "Lustre filesystem '%s' not found",
634 llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
635 if ((dir = opendir(pathname)) == NULL) {
636 llapi_err(LLAPI_MSG_ERROR, "Could not open pool list for '%s'",
642 rc = readdir_r(dir, &pool, &cookie);
645 llapi_err(LLAPI_MSG_ERROR,
646 "Error reading pool list for '%s'", name);
648 } else if ((rc == 0) && (cookie == NULL))
649 /* end of directory */
652 /* ignore . and .. */
653 if (!strcmp(pool.d_name, ".") || !strcmp(pool.d_name, ".."))
656 /* check output bounds */
657 if (nb_entries >= list_size)
660 /* +2 for '.' and final '\0' */
661 if (used + strlen(pool.d_name) + strlen(fsname) + 2
665 sprintf(buffer + used, "%s.%s", fsname, pool.d_name);
666 poollist[nb_entries] = buffer + used;
667 used += strlen(pool.d_name) + strlen(fsname) + 2;
675 /* wrapper for lfs.c and obd.c */
676 int llapi_poollist(const char *name)
678 /* list of pool names (assume that pool count is smaller
680 char *list[FIND_MAX_OSTS];
682 /* fsname-OST0000_UUID < 32 char, 1 per OST */
683 int bufsize = FIND_MAX_OSTS * 32;
686 buffer = malloc(bufsize);
690 if ((name[0] == '/') || (strchr(name, '.') == NULL))
691 /* name is a path or fsname */
692 nb = llapi_get_poollist(name, list, FIND_MAX_OSTS, buffer,
695 /* name is a pool name (<fsname>.<poolname>) */
696 nb = llapi_get_poolmembers(name, list, FIND_MAX_OSTS, buffer,
699 for (i = 0; i < nb; i++)
700 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", list[i]);
703 return (nb < 0 ? nb : 0);
707 typedef int (semantic_func_t)(char *path, DIR *parent, DIR *d,
708 void *data, cfs_dirent_t *de);
710 #define MAX_LOV_UUID_COUNT max(LOV_MAX_STRIPE_COUNT, 1000)
711 #define OBD_NOT_FOUND (-1)
713 static int common_param_init(struct find_param *param)
715 param->lumlen = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC_V3);
716 if ((param->lmd = malloc(sizeof(lstat_t) + param->lumlen)) == NULL) {
717 llapi_err(LLAPI_MSG_ERROR,
718 "error: allocation of %d bytes for ioctl",
719 sizeof(lstat_t) + param->lumlen);
723 param->got_uuids = 0;
724 param->obdindexes = NULL;
725 param->obdindex = OBD_NOT_FOUND;
729 static void find_param_fini(struct find_param *param)
731 if (param->obdindexes)
732 free(param->obdindexes);
738 int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_name)
740 int rc = ioctl(fd, OBD_IOC_GETNAME, lov_name);
743 llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name.");
748 int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid)
752 fd = open(path, O_RDONLY);
755 llapi_err(LLAPI_MSG_ERROR, "error opening %s", path);
759 rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
767 * If uuidp is NULL, return the number of available obd uuids.
768 * If uuidp is non-NULL, then it will return the uuids of the obds. If
769 * there are more OSTs then allocated to uuidp, then an error is returned with
770 * the ost_count set to number of available obd uuids.
772 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
774 struct obd_uuid lov_name;
777 int rc = 0, index = 0;
779 /* Get the lov name */
780 rc = llapi_file_fget_lov_uuid(fd, &lov_name);
784 /* Now get the ost uuids from /proc */
785 snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
787 fp = fopen(buf, "r");
790 llapi_err(LLAPI_MSG_ERROR, "error: opening '%s'", buf);
794 while (fgets(buf, sizeof(buf), fp) != NULL) {
795 if (uuidp && (index < *ost_count)) {
796 if (sscanf(buf, "%d: %s", &index, uuidp[index].uuid) <2)
804 if (uuidp && (index >= *ost_count))
811 int llapi_get_obd_count(char *mnt, int *count, int is_mdt)
818 llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
823 rc = ioctl(dirfd(root), LL_IOC_GETOBDCOUNT, count);
829 /* Here, param->obduuid points to a single obduuid, the index of which is
830 * returned in param->obdindex */
831 static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param)
833 struct obd_uuid lov_uuid;
834 char uuid[sizeof(struct obd_uuid)];
839 /* Get the lov name */
840 rc = llapi_file_fget_lov_uuid(dirfd(dir), &lov_uuid);
842 if (errno != ENOTTY) {
844 llapi_err(LLAPI_MSG_ERROR,
845 "error: can't get lov name: %s", dname);
852 param->got_uuids = 1;
854 /* Now get the ost uuids from /proc */
855 snprintf(buf, sizeof(buf), "/proc/fs/lustre/lov/%s/target_obd",
857 fp = fopen(buf, "r");
860 llapi_err(LLAPI_MSG_ERROR, "error: opening '%s'", buf);
864 if (!param->obduuid && !param->quiet && !param->obds_printed)
865 llapi_printf(LLAPI_MSG_NORMAL, "OBDS:\n");
867 while (fgets(buf, sizeof(buf), fp) != NULL) {
868 if (sscanf(buf, "%d: %s", &index, uuid) < 2)
871 if (param->obduuid) {
872 if (strncmp(param->obduuid->uuid, uuid,
873 sizeof(uuid)) == 0) {
874 param->obdindex = index;
877 } else if (!param->quiet && !param->obds_printed) {
878 /* Print everything */
879 llapi_printf(LLAPI_MSG_NORMAL, "%s", buf);
882 param->obds_printed = 1;
886 if (!param->quiet && param->obduuid &&
887 (param->obdindex == OBD_NOT_FOUND)) {
888 llapi_err_noerrno(LLAPI_MSG_ERROR,
889 "error: %s: unknown obduuid: %s",
890 __FUNCTION__, param->obduuid->uuid);
897 /* In this case, param->obduuid will be an array of obduuids and
898 * obd index for all these obduuids will be returned in
899 * param->obdindexes */
900 static int setup_obd_indexes(DIR *dir, struct find_param *param)
902 struct obd_uuid *uuids = NULL;
903 int obdcount = INIT_ALLOC_NUM_OSTS;
904 int ret, obd_valid = 0, obdnum, i;
906 uuids = (struct obd_uuid *)malloc(INIT_ALLOC_NUM_OSTS *
907 sizeof(struct obd_uuid));
912 ret = llapi_lov_get_uuids(dirfd(dir), uuids,
915 struct obd_uuid *uuids_temp;
917 if (ret == -EOVERFLOW) {
918 uuids_temp = realloc(uuids, obdcount *
919 sizeof(struct obd_uuid));
920 if (uuids_temp != NULL)
921 goto retry_get_uuids;
926 llapi_err(LLAPI_MSG_ERROR, "get ost uuid failed");
930 param->obdindexes = malloc(param->num_obds * sizeof(param->obdindex));
931 if (param->obdindexes == NULL)
934 for (obdnum = 0; obdnum < param->num_obds; obdnum++) {
935 for (i = 0; i <= obdcount; i++) {
936 if (strcmp((char *)¶m->obduuid[obdnum].uuid,
937 (char *)&uuids[i]) == 0) {
938 param->obdindexes[obdnum] = i;
944 param->obdindexes[obdnum] = OBD_NOT_FOUND;
948 param->obdindex = OBD_NOT_FOUND;
950 param->obdindex = obd_valid;
952 param->got_uuids = 1;
957 static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
958 int is_dir, int verbose, int quiet,
961 char *prefix = is_dir ? "" : "lmm_";
962 char nl = is_dir ? ' ' : '\n';
965 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
967 if ((verbose & VERBOSE_DETAIL) && !is_dir) {
968 llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic: 0x%08X\n",
970 llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_gr: "LPX64"\n",
972 llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: "LPX64"\n",
976 if (verbose & VERBOSE_COUNT) {
978 llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
980 llapi_printf(LLAPI_MSG_NORMAL, "%u%c",
981 (int)lum->lmm_stripe_count, nl);
984 if (verbose & VERBOSE_SIZE) {
986 llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
988 llapi_printf(LLAPI_MSG_NORMAL, "%u%c", lum->lmm_stripe_size,
992 if ((verbose & VERBOSE_DETAIL) && !is_dir) {
993 llapi_printf(LLAPI_MSG_NORMAL, "lmm_stripe_pattern: %x%c",
994 lum->lmm_pattern, nl);
997 if (verbose & VERBOSE_OFFSET) {
999 llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
1001 llapi_printf(LLAPI_MSG_NORMAL, "%u%c",
1002 lum->lmm_objects[0].l_ost_idx, nl);
1005 if ((verbose & VERBOSE_POOL) && (pool_name != NULL))
1006 llapi_printf(LLAPI_MSG_NORMAL, "pool: %s%c", pool_name, nl);
1009 llapi_printf(LLAPI_MSG_NORMAL, "\n");
1012 void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
1013 struct lov_user_ost_data_v1 *objects,
1014 char *path, int is_dir,
1015 int obdindex, int quiet, int header, int body)
1017 int i, obdstripe = 0;
1019 if (obdindex != OBD_NOT_FOUND) {
1020 for (i = 0; !is_dir && i < lum->lmm_stripe_count; i++) {
1021 if (obdindex == objects[i].l_ost_idx) {
1022 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
1029 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
1033 /* if it's a directory */
1035 if (obdstripe == 1) {
1036 if (lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) {
1037 llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
1038 lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR;
1040 /* maintain original behavior */
1042 header |= VERBOSE_ALL;
1043 lov_dump_user_lmm_header(lum, path, is_dir, header,
1049 if (header && (obdstripe == 1))
1050 lov_dump_user_lmm_header(lum, NULL, is_dir, header, quiet,
1054 if ((!quiet) && (obdstripe == 1))
1055 llapi_printf(LLAPI_MSG_NORMAL,
1056 "\tobdidx\t\t objid\t\tobjid\t\t group\n");
1058 for (i = 0; i < lum->lmm_stripe_count; i++) {
1059 int idx = objects[i].l_ost_idx;
1060 long long oid = objects[i].l_object_id;
1061 long long gr = objects[i].l_object_gr;
1062 if ((obdindex == OBD_NOT_FOUND) || (obdindex == idx))
1063 llapi_printf(LLAPI_MSG_NORMAL,
1064 "\t%6u\t%14llu\t%#13llx\t%14llu%s\n",
1066 obdindex == idx ? " *" : "");
1068 llapi_printf(LLAPI_MSG_NORMAL, "\n");
1072 void lov_dump_user_lmm_join(struct lov_user_md_v1 *lum, char *path,
1073 int is_dir, int obdindex, int quiet,
1074 int header, int body)
1076 struct lov_user_md_join *lumj = (struct lov_user_md_join *)lum;
1077 int i, obdstripe = 0;
1079 if (obdindex != OBD_NOT_FOUND) {
1080 for (i = 0; i < lumj->lmm_stripe_count; i++) {
1081 if (obdindex == lumj->lmm_objects[i].l_ost_idx) {
1082 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
1089 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
1093 if (header && obdstripe == 1) {
1094 lov_dump_user_lmm_header(lum, NULL, 0, header, quiet, NULL);
1096 llapi_printf(LLAPI_MSG_NORMAL, "lmm_extent_count: %x\n",
1097 lumj->lmm_extent_count);
1101 unsigned long long start = -1, end = 0;
1102 if (!quiet && obdstripe == 1)
1103 llapi_printf(LLAPI_MSG_NORMAL,
1104 "joined\tobdidx\t\t objid\t\tobjid\t\t "
1105 "group\t\tstart\t\tend\n");
1106 for (i = 0; i < lumj->lmm_stripe_count; i++) {
1107 int idx = lumj->lmm_objects[i].l_ost_idx;
1108 long long oid = lumj->lmm_objects[i].l_object_id;
1109 long long gr = lumj->lmm_objects[i].l_object_gr;
1110 if (obdindex == OBD_NOT_FOUND || obdindex == idx)
1111 llapi_printf(LLAPI_MSG_NORMAL,
1112 "\t%6u\t%14llu\t%#13llx\t%14llu%s",
1114 obdindex == idx ? " *" : "");
1115 if (start != lumj->lmm_objects[i].l_extent_start ||
1116 end != lumj->lmm_objects[i].l_extent_end) {
1117 start = lumj->lmm_objects[i].l_extent_start;
1118 llapi_printf(LLAPI_MSG_NORMAL,"\t%14llu",start);
1119 end = lumj->lmm_objects[i].l_extent_end;
1120 if (end == (unsigned long long)-1)
1121 llapi_printf(LLAPI_MSG_NORMAL,
1124 llapi_printf(LLAPI_MSG_NORMAL,
1127 llapi_printf(LLAPI_MSG_NORMAL, "\t\t\t\t\n");
1130 llapi_printf(LLAPI_MSG_NORMAL, "\n");
1134 void llapi_lov_dump_user_lmm(struct find_param *param,
1135 char *path, int is_dir)
1137 switch(*(__u32 *)¶m->lmd->lmd_lmm) { /* lum->lmm_magic */
1138 case LOV_USER_MAGIC_V1:
1139 lov_dump_user_lmm_v1v3(¶m->lmd->lmd_lmm, NULL,
1140 param->lmd->lmd_lmm.lmm_objects,
1142 param->obdindex, param->quiet,
1144 (param->verbose || !param->obduuid));
1146 case LOV_USER_MAGIC_JOIN:
1147 lov_dump_user_lmm_join(¶m->lmd->lmd_lmm, path, is_dir,
1148 param->obdindex, param->quiet,
1150 (param->verbose || !param->obduuid));
1152 case LOV_USER_MAGIC_V3: {
1153 char pool_name[LOV_MAXPOOLNAME + 1];
1154 struct lov_user_ost_data_v1 *objects;
1155 struct lov_user_md_v3 *lmmv3 = (void *)¶m->lmd->lmd_lmm;
1157 strncpy(pool_name, lmmv3->lmm_pool_name, LOV_MAXPOOLNAME);
1158 pool_name[LOV_MAXPOOLNAME] = '\0';
1159 objects = lmmv3->lmm_objects;
1160 lov_dump_user_lmm_v1v3(¶m->lmd->lmd_lmm, pool_name,
1161 objects, path, is_dir,
1162 param->obdindex, param->quiet,
1164 (param->verbose || !param->obduuid));
1168 llapi_printf(LLAPI_MSG_NORMAL, "unknown lmm_magic: %#x "
1169 "(expecting one of %#x %#x %#x)\n",
1170 *(__u32 *)¶m->lmd->lmd_lmm,
1171 LOV_USER_MAGIC_V1, LOV_USER_MAGIC_JOIN,
1177 int llapi_file_get_stripe(const char *path, struct lov_user_md *lum)
1183 fname = strrchr(path, '/');
1185 /* It should be a file (or other non-directory) */
1186 if (fname == NULL) {
1187 dname = (char *)malloc(2);
1191 fname = (char *)path;
1193 dname = (char *)malloc(fname - path + 1);
1196 strncpy(dname, path, fname - path);
1197 dname[fname - path] = '\0';
1201 if ((fd = open(dname, O_RDONLY)) == -1) {
1207 strcpy((char *)lum, fname);
1208 if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
1211 if (close(fd) == -1 && rc == 0)
1219 int llapi_file_lookup(int dirfd, const char *name)
1221 struct obd_ioctl_data data = { 0 };
1226 if (dirfd < 0 || name == NULL)
1229 data.ioc_version = OBD_IOCTL_VERSION;
1230 data.ioc_len = sizeof(data);
1231 data.ioc_inlbuf1 = (char *)name;
1232 data.ioc_inllen1 = strlen(name) + 1;
1234 rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
1236 llapi_err(LLAPI_MSG_ERROR,
1237 "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
1242 return ioctl(dirfd, IOC_MDC_LOOKUP, buf);
1245 int llapi_mds_getfileinfo(char *path, DIR *parent,
1246 struct lov_user_mds_data *lmd)
1248 lstat_t *st = &lmd->lmd_st;
1249 char *fname = strrchr(path, '/');
1255 fname = (fname == NULL ? path : fname + 1);
1256 /* retrieve needed file info */
1257 strncpy((char *)lmd, fname,
1258 lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC));
1259 ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd);
1262 if (errno == ENOTTY) {
1263 /* ioctl is not supported, it is not a lustre fs.
1264 * Do the regular lstat(2) instead. */
1265 ret = lstat_f(path, st);
1267 llapi_err(LLAPI_MSG_ERROR,
1268 "error: %s: lstat failed for %s",
1269 __FUNCTION__, path);
1272 } else if (errno == ENOENT) {
1273 llapi_err(LLAPI_MSG_WARN,
1274 "warning: %s: %s does not exist",
1275 __FUNCTION__, path);
1278 llapi_err(LLAPI_MSG_ERROR,
1279 "error: %s: IOC_MDC_GETFILEINFO failed for %s",
1280 __FUNCTION__, path);
1288 static DIR *opendir_parent(char *path)
1294 fname = strrchr(path, '/');
1296 return opendir(".");
1300 parent = opendir(path);
1305 static int llapi_semantic_traverse(char *path, int size, DIR *parent,
1306 semantic_func_t sem_init,
1307 semantic_func_t sem_fini, void *data,
1318 if (!d && errno != ENOTDIR) {
1319 llapi_err(LLAPI_MSG_ERROR, "%s: Failed to open '%s'",
1320 __FUNCTION__, path);
1322 } else if (!d && !parent) {
1323 /* ENOTDIR. Open the parent dir. */
1324 p = opendir_parent(path);
1326 GOTO(out, ret = -EINVAL);
1329 if (sem_init && (ret = sem_init(path, parent ?: p, d, data, de)))
1335 while ((dent = readdir64(d)) != NULL) {
1336 ((struct find_param *)data)->have_fileinfo = 0;
1338 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
1341 /* Don't traverse .lustre directory */
1342 if (!(strcmp(dent->d_name, dot_lustre_name)))
1346 if ((len + dent->d_reclen + 2) > size) {
1347 llapi_err(LLAPI_MSG_ERROR,
1348 "error: %s: string buffer is too small",
1353 strcat(path, dent->d_name);
1355 if (dent->d_type == DT_UNKNOWN) {
1356 lstat_t *st = &((struct find_param *)data)->lmd->lmd_st;
1358 ret = llapi_mds_getfileinfo(path, d,
1359 ((struct find_param *)data)->lmd);
1361 ((struct find_param *)data)->have_fileinfo = 1;
1363 llapi_filetype_dir_table[st->st_mode &
1370 switch (dent->d_type) {
1372 llapi_err(LLAPI_MSG_ERROR,
1373 "error: %s: '%s' is UNKNOWN type %d",
1374 __FUNCTION__, dent->d_name, dent->d_type);
1377 ret = llapi_semantic_traverse(path, size, d, sem_init,
1378 sem_fini, data, dent);
1385 ret = sem_init(path, d, NULL, data, dent);
1389 if (sem_fini && ret == 0)
1390 sem_fini(path, d, NULL, data, dent);
1398 sem_fini(path, parent, d, data, de);
1407 /* Check if the value matches 1 of the given criteria (e.g. --atime +/-N).
1408 * @mds indicates if this is MDS timestamps and there are attributes on OSTs.
1410 * The result is -1 if it does not match, 0 if not yet clear, 1 if matches.
1411 * The table below gives the answers for the specified parameters (value and
1412 * sign), 1st column is the answer for the MDS value, the 2nd is for the OST:
1413 * --------------------------------------
1414 * 1 | file > limit; sign > 0 | -1 / -1 |
1415 * 2 | file = limit; sign > 0 | ? / 1 |
1416 * 3 | file < limit; sign > 0 | ? / 1 |
1417 * 4 | file > limit; sign = 0 | -1 / -1 |
1418 * 5 | file = limit; sign = 0 | ? / 1 | <- (see the Note below)
1419 * 6 | file < limit; sign = 0 | ? / -1 |
1420 * 7 | file > limit; sign < 0 | 1 / 1 |
1421 * 8 | file = limit; sign < 0 | ? / -1 |
1422 * 9 | file < limit; sign < 0 | ? / -1 |
1423 * --------------------------------------
1424 * Note: 5th actually means that the value is within the interval
1425 * (limit - margin, limit]. */
1426 static int find_value_cmp(unsigned int file, unsigned int limit, int sign,
1427 unsigned long long margin, int mds)
1435 if (file <= limit && file + margin > limit)
1437 if (file + margin <= limit)
1438 return mds ? 0 : -1;
1451 /* Check if the file time matches all the given criteria (e.g. --atime +/-N).
1452 * Return -1 or 1 if file timestamp does not or does match the given criteria
1453 * correspondingly. Return 0 if the MDS time is being checked and there are
1454 * attributes on OSTs and it is not yet clear if the timespamp matches.
1456 * If 0 is returned, we need to do another RPC to the OSTs to obtain the
1457 * updated timestamps. */
1458 static int find_time_check(lstat_t *st, struct find_param *param, int mds)
1463 /* Check if file is accepted. */
1465 ret = find_value_cmp(st->st_atime, param->atime,
1466 param->asign, 24 * 60 * 60, mds);
1473 ret = find_value_cmp(st->st_mtime, param->mtime,
1474 param->msign, 24 * 60 * 60, mds);
1478 /* If the previous check matches, but this one is not yet clear,
1479 * we should return 0 to do an RPC on OSTs. */
1485 ret = find_value_cmp(st->st_ctime, param->ctime,
1486 param->csign, 24 * 60 * 60, mds);
1490 /* If the previous check matches, but this one is not yet clear,
1491 * we should return 0 to do an RPC on OSTs. */
1499 static int cb_find_init(char *path, DIR *parent, DIR *dir,
1500 void *data, cfs_dirent_t *de)
1502 struct find_param *param = (struct find_param *)data;
1503 int decision = 1; /* 1 is accepted; -1 is rejected. */
1504 lstat_t *st = ¶m->lmd->lmd_st;
1506 int checked_type = 0;
1509 LASSERT(parent != NULL || dir != NULL);
1511 param->lmd->lmd_lmm.lmm_stripe_count = 0;
1513 /* If a regular expression is presented, make the initial decision */
1514 if (param->pattern != NULL) {
1515 char *fname = strrchr(path, '/');
1516 fname = (fname == NULL ? path : fname + 1);
1517 ret = fnmatch(param->pattern, fname, 0);
1518 if ((ret == FNM_NOMATCH && !param->exclude_pattern) ||
1519 (ret == 0 && param->exclude_pattern))
1523 /* See if we can check the file type from the dirent. */
1524 if (param->type && de != NULL && de->d_type != DT_UNKNOWN &&
1525 de->d_type < DT_MAX) {
1527 if (llapi_dir_filetype_table[de->d_type] == param->type) {
1528 if (param->exclude_type)
1531 if (!param->exclude_type)
1537 /* If a time or OST should be checked, the decision is not taken yet. */
1538 if (param->atime || param->ctime || param->mtime || param->obduuid ||
1543 /* Request MDS for the stat info. */
1544 if (param->have_fileinfo == 0) {
1546 /* retrieve needed file info */
1547 ret = ioctl(dirfd(dir), LL_IOC_MDC_GETINFO,
1548 (void *)param->lmd);
1550 char *fname = strrchr(path, '/');
1551 fname = (fname == NULL ? path : fname + 1);
1553 /* retrieve needed file info */
1554 strncpy((char *)param->lmd, fname, param->lumlen);
1555 ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO,
1556 (void *)param->lmd);
1561 if (errno == ENOTTY) {
1562 /* ioctl is not supported, it is not a lustre fs.
1563 * Do the regular lstat(2) instead. */
1565 ret = lstat_f(path, st);
1567 llapi_err(LLAPI_MSG_ERROR,
1568 "error: %s: lstat failed for %s",
1569 __FUNCTION__, path);
1572 } else if (errno == ENOENT) {
1573 llapi_err(LLAPI_MSG_WARN,
1574 "warning: %s: %s does not exist",
1575 __FUNCTION__, path);
1578 llapi_err(LLAPI_MSG_ERROR,"error: %s: %s failed for %s",
1579 __FUNCTION__, dir ? "LL_IOC_MDC_GETINFO" :
1580 "IOC_MDC_GETFILEINFO", path);
1585 if (param->type && !checked_type) {
1586 if ((st->st_mode & S_IFMT) == param->type) {
1587 if (param->exclude_type)
1590 if (!param->exclude_type)
1596 if (param->obduuid) {
1597 if (lustre_fs && param->got_uuids &&
1598 param->st_dev != st->st_dev) {
1599 /* A lustre/lustre mount point is crossed. */
1600 param->got_uuids = 0;
1601 param->obds_printed = 0;
1602 param->obdindex = OBD_NOT_FOUND;
1605 if (lustre_fs && !param->got_uuids) {
1606 ret = setup_obd_indexes(dir ? dir : parent, param);
1610 param->st_dev = st->st_dev;
1611 } else if (!lustre_fs && param->got_uuids) {
1612 /* A lustre/non-lustre mount point is crossed. */
1613 param->got_uuids = 0;
1614 param->obdindex = OBD_NOT_FOUND;
1618 /* If an OBD UUID is specified but no one matches, skip this file. */
1619 if (param->obduuid && param->obdindex == OBD_NOT_FOUND)
1622 /* If a OST UUID is given, and some OST matches, check it here. */
1623 if (param->obdindex != OBD_NOT_FOUND) {
1624 if (!S_ISREG(st->st_mode))
1627 /* Only those files should be accepted, which have a
1628 * stripe on the specified OST. */
1629 if (!param->lmd->lmd_lmm.lmm_stripe_count) {
1633 struct lov_user_ost_data_v1 *lmm_objects;
1635 if (param->lmd->lmd_lmm.lmm_magic ==
1636 LOV_USER_MAGIC_V3) {
1637 struct lov_user_md_v3 *lmmv3 =
1638 (void *)¶m->lmd->lmd_lmm;
1640 lmm_objects = lmmv3->lmm_objects;
1642 lmm_objects = param->lmd->lmd_lmm.lmm_objects;
1646 i < param->lmd->lmd_lmm.lmm_stripe_count; i++) {
1647 for (j = 0; j < param->num_obds; j++) {
1648 if (param->obdindexes[j] ==
1649 lmm_objects[i].l_ost_idx)
1654 if (i == param->lmd->lmd_lmm.lmm_stripe_count)
1659 if (param->check_uid) {
1660 if (st->st_uid == param->uid) {
1661 if (param->exclude_uid)
1664 if (!param->exclude_uid)
1669 if (param->check_gid) {
1670 if (st->st_gid == param->gid) {
1671 if (param->exclude_gid)
1674 if (!param->exclude_gid)
1679 if (param->check_pool) {
1680 struct lov_user_md_v3 *lmmv3 = (void *)¶m->lmd->lmd_lmm;
1682 /* empty requested pool is taken as no pool search => V1 */
1683 if (((param->lmd->lmd_lmm.lmm_magic == LOV_USER_MAGIC_V1) &&
1684 (param->poolname[0] == '\0')) ||
1685 ((param->lmd->lmd_lmm.lmm_magic == LOV_USER_MAGIC_V3) &&
1686 (strncmp(lmmv3->lmm_pool_name,
1687 param->poolname, LOV_MAXPOOLNAME) == 0)) ||
1688 ((param->lmd->lmd_lmm.lmm_magic == LOV_USER_MAGIC_V3) &&
1689 (strcmp(param->poolname, "*") == 0))) {
1690 if (param->exclude_pool)
1693 if (!param->exclude_pool)
1698 /* Check the time on mds. */
1702 for_mds = lustre_fs ? (S_ISREG(st->st_mode) &&
1703 param->lmd->lmd_lmm.lmm_stripe_count)
1705 decision = find_time_check(st, param, for_mds);
1709 /* If file still fits the request, ask ost for updated info.
1710 The regular stat is almost of the same speed as some new
1711 'glimpse-size-ioctl'. */
1712 if (!decision && S_ISREG(st->st_mode) &&
1713 (param->lmd->lmd_lmm.lmm_stripe_count || param->size)) {
1714 if (param->obdindex != OBD_NOT_FOUND) {
1715 /* Check whether the obd is active or not, if it is
1716 * not active, just print the object affected by this
1719 struct obd_statfs stat_buf;
1720 struct obd_uuid uuid_buf;
1722 memset(&stat_buf, 0, sizeof(struct obd_statfs));
1723 memset(&uuid_buf, 0, sizeof(struct obd_uuid));
1724 ret = llapi_obd_statfs(path, LL_STATFS_LOV,
1725 param->obdindex, &stat_buf,
1728 if (ret == -ENODATA || ret == -ENODEV
1731 llapi_printf(LLAPI_MSG_NORMAL,
1732 "obd_uuid: %s failed %s ",
1733 param->obduuid->uuid,
1739 ret = ioctl(dirfd(dir), IOC_LOV_GETINFO,
1740 (void *)param->lmd);
1741 } else if (parent) {
1742 ret = ioctl(dirfd(parent), IOC_LOV_GETINFO,
1743 (void *)param->lmd);
1747 if (errno == ENOENT) {
1748 llapi_err(LLAPI_MSG_ERROR,
1749 "warning: %s: %s does not exist",
1750 __FUNCTION__, path);
1753 llapi_err(LLAPI_MSG_ERROR,
1754 "%s: IOC_LOV_GETINFO on %s failed",
1755 __FUNCTION__, path);
1760 /* Check the time on osc. */
1761 decision = find_time_check(st, param, 0);
1767 decision = find_value_cmp(st->st_size, param->size,
1768 param->size_sign, param->size_units,
1772 if (decision != -1) {
1773 llapi_printf(LLAPI_MSG_NORMAL, "%s", path);
1775 llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0');
1777 llapi_printf(LLAPI_MSG_NORMAL, "\n");
1781 /* Do not get down anymore? */
1782 if (param->depth == param->maxdepth)
1789 static int cb_common_fini(char *path, DIR *parent, DIR *d, void *data,
1792 struct find_param *param = (struct find_param *)data;
1797 int llapi_find(char *path, struct find_param *param)
1800 int ret, len = strlen(path);
1802 if (len > PATH_MAX) {
1803 llapi_err(LLAPI_MSG_ERROR, "%s: Path name '%s' is too long",
1804 __FUNCTION__, path);
1808 buf = (char *)malloc(PATH_MAX + 1);
1812 ret = common_param_init(param);
1820 strncpy(buf, path, PATH_MAX + 1);
1821 ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_find_init,
1822 cb_common_fini, param, NULL);
1824 find_param_fini(param);
1826 return ret < 0 ? ret : 0;
1829 static int cb_getstripe(char *path, DIR *parent, DIR *d, void *data,
1832 struct find_param *param = (struct find_param *)data;
1835 LASSERT(parent != NULL || d != NULL);
1838 if (!param->got_uuids) {
1839 ret = setup_obd_uuid(d ? d : parent, path, param);
1845 ret = ioctl(dirfd(d), LL_IOC_LOV_GETSTRIPE,
1846 (void *)¶m->lmd->lmd_lmm);
1847 } else if (parent) {
1848 char *fname = strrchr(path, '/');
1849 fname = (fname == NULL ? path : fname + 1);
1851 strncpy((char *)¶m->lmd->lmd_lmm, fname, param->lumlen);
1852 ret = ioctl(dirfd(parent), IOC_MDC_GETFILESTRIPE,
1853 (void *)¶m->lmd->lmd_lmm);
1857 if (errno == ENODATA) {
1858 if (!param->obduuid && !param->quiet)
1859 llapi_printf(LLAPI_MSG_NORMAL,
1860 "%s has no stripe info\n", path);
1862 } else if (errno == ENOTTY) {
1863 llapi_err(LLAPI_MSG_ERROR,
1864 "%s: '%s' not on a Lustre fs?",
1865 __FUNCTION__, path);
1866 } else if (errno == ENOENT) {
1867 llapi_err(LLAPI_MSG_WARN,
1868 "warning: %s: %s does not exist",
1869 __FUNCTION__, path);
1872 llapi_err(LLAPI_MSG_ERROR,
1873 "error: %s: %s failed for %s",
1874 __FUNCTION__, d ? "LL_IOC_LOV_GETSTRIPE" :
1875 "IOC_MDC_GETFILESTRIPE", path);
1881 llapi_lov_dump_user_lmm(param, path, d ? 1 : 0);
1883 /* Do not get down anymore? */
1884 if (param->depth == param->maxdepth)
1891 int llapi_getstripe(char *path, struct find_param *param)
1894 int ret = 0, len = strlen(path);
1896 if (len > PATH_MAX) {
1897 llapi_err(LLAPI_MSG_ERROR,
1898 "%s: Path name '%s' is too long",
1899 __FUNCTION__, path);
1903 buf = (char *)malloc(PATH_MAX + 1);
1907 ret = common_param_init(param);
1915 strncpy(buf, path, PATH_MAX + 1);
1916 ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_getstripe,
1917 cb_common_fini, param, NULL);
1918 find_param_fini(param);
1920 return ret < 0 ? ret : 0;
1923 int llapi_obd_statfs(char *path, __u32 type, __u32 index,
1924 struct obd_statfs *stat_buf,
1925 struct obd_uuid *uuid_buf)
1928 char raw[OBD_MAX_IOCTL_BUFFER] = {'\0'};
1930 struct obd_ioctl_data data = { 0 };
1933 data.ioc_inlbuf1 = (char *)&type;
1934 data.ioc_inllen1 = sizeof(__u32);
1935 data.ioc_inlbuf2 = (char *)&index;
1936 data.ioc_inllen2 = sizeof(__u32);
1937 data.ioc_pbuf1 = (char *)stat_buf;
1938 data.ioc_plen1 = sizeof(struct obd_statfs);
1939 data.ioc_pbuf2 = (char *)uuid_buf;
1940 data.ioc_plen2 = sizeof(struct obd_uuid);
1942 if ((rc = obd_ioctl_pack(&data, &rawbuf, sizeof(raw))) != 0) {
1943 llapi_err(LLAPI_MSG_ERROR,
1944 "llapi_obd_statfs: error packing ioctl data");
1948 fd = open(path, O_RDONLY);
1949 if (errno == EISDIR)
1950 fd = open(path, O_DIRECTORY | O_RDONLY);
1953 rc = errno ? -errno : -EBADF;
1954 llapi_err(LLAPI_MSG_ERROR, "error: %s: opening '%s'",
1955 __FUNCTION__, path);
1958 rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
1960 rc = errno ? -errno : -EINVAL;
1966 #define MAX_STRING_SIZE 128
1967 #define DEVICES_LIST "/proc/fs/lustre/devices"
1969 int llapi_ping(char *obd_type, char *obd_name)
1971 char path[MAX_STRING_SIZE];
1975 snprintf(path, MAX_STRING_SIZE, "/proc/fs/lustre/%s/%s/ping",
1976 obd_type, obd_name);
1978 fd = open(path, O_WRONLY);
1981 llapi_err(LLAPI_MSG_ERROR, "error opening %s", path);
1985 rc = write(fd, buf, 1);
1993 int llapi_target_iterate(int type_num, char **obd_type,void *args,llapi_cb_t cb)
1995 char buf[MAX_STRING_SIZE];
1996 FILE *fp = fopen(DEVICES_LIST, "r");
2001 llapi_err(LLAPI_MSG_ERROR, "error: opening "DEVICES_LIST);
2005 while (fgets(buf, sizeof(buf), fp) != NULL) {
2006 char *obd_type_name = NULL;
2007 char *obd_name = NULL;
2008 char *obd_uuid = NULL;
2010 struct obd_ioctl_data datal = { 0, };
2011 struct obd_statfs osfs_buffer;
2013 while(bufp[0] == ' ')
2016 for(i = 0; i < 3; i++) {
2017 obd_type_name = strsep(&bufp, " ");
2019 obd_name = strsep(&bufp, " ");
2020 obd_uuid = strsep(&bufp, " ");
2022 memset(&osfs_buffer, 0, sizeof (osfs_buffer));
2024 datal.ioc_pbuf1 = (char *)&osfs_buffer;
2025 datal.ioc_plen1 = sizeof(osfs_buffer);
2027 for (i = 0; i < type_num; i++) {
2028 if (strcmp(obd_type_name, obd_type[i]) != 0)
2031 cb(obd_type_name, obd_name, obd_uuid, args);
2038 static void do_target_check(char *obd_type_name, char *obd_name,
2039 char *obd_uuid, void *args)
2043 rc = llapi_ping(obd_type_name, obd_name);
2044 if (rc == ENOTCONN) {
2045 llapi_printf(LLAPI_MSG_NORMAL, "%s inactive.\n", obd_name);
2047 llapi_err(LLAPI_MSG_ERROR, "error: check '%s'", obd_name);
2049 llapi_printf(LLAPI_MSG_NORMAL, "%s active.\n", obd_name);
2053 int llapi_target_check(int type_num, char **obd_type, char *dir)
2055 return llapi_target_iterate(type_num, obd_type, NULL, do_target_check);
2058 #undef MAX_STRING_SIZE
2060 int llapi_catinfo(char *dir, char *keyword, char *node_name)
2062 char raw[OBD_MAX_IOCTL_BUFFER];
2063 char out[LLOG_CHUNK_SIZE];
2065 struct obd_ioctl_data data = { 0 };
2070 sprintf(key, "%s", keyword);
2071 memset(raw, 0, sizeof(raw));
2072 memset(out, 0, sizeof(out));
2073 data.ioc_inlbuf1 = key;
2074 data.ioc_inllen1 = strlen(key) + 1;
2076 data.ioc_inlbuf2 = node_name;
2077 data.ioc_inllen2 = strlen(node_name) + 1;
2079 data.ioc_pbuf1 = out;
2080 data.ioc_plen1 = sizeof(out);
2081 rc = obd_ioctl_pack(&data, &buf, sizeof(raw));
2085 root = opendir(dir);
2088 llapi_err(LLAPI_MSG_ERROR, "open %s failed", dir);
2092 rc = ioctl(dirfd(root), OBD_IOC_LLOG_CATINFO, buf);
2094 llapi_err(LLAPI_MSG_ERROR, "ioctl OBD_IOC_CATINFO failed");
2096 llapi_printf(LLAPI_MSG_NORMAL, "%s", data.ioc_pbuf1);
2102 /* Is this a lustre fs? */
2103 int llapi_is_lustre_mnttype(const char *type)
2105 return (strcmp(type, "lustre") == 0 || strcmp(type,"lustre_lite") == 0);
2108 /* Is this a lustre client fs? */
2109 int llapi_is_lustre_mnt(struct mntent *mnt)
2111 return (llapi_is_lustre_mnttype(mnt->mnt_type) &&
2112 strstr(mnt->mnt_fsname, ":/") != NULL);
2115 int llapi_quotacheck(char *mnt, int check_type)
2120 root = opendir(mnt);
2122 llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
2126 rc = ioctl(dirfd(root), LL_IOC_QUOTACHECK, check_type);
2132 int llapi_poll_quotacheck(char *mnt, struct if_quotacheck *qchk)
2138 root = opendir(mnt);
2140 llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
2145 rc = ioctl(dirfd(root), LL_IOC_POLL_QUOTACHECK, qchk);
2149 if (poll_intvl < 30)
2157 int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
2162 root = opendir(mnt);
2164 llapi_err(LLAPI_MSG_ERROR, "open %s failed", mnt);
2168 rc = ioctl(dirfd(root), LL_IOC_QUOTACTL, qctl);
2174 static int cb_quotachown(char *path, DIR *parent, DIR *d, void *data,
2177 struct find_param *param = (struct find_param *)data;
2181 LASSERT(parent != NULL || d != NULL);
2184 rc = ioctl(dirfd(d), LL_IOC_MDC_GETINFO,
2185 (void *)param->lmd);
2186 } else if (parent) {
2187 char *fname = strrchr(path, '/');
2188 fname = (fname == NULL ? path : fname + 1);
2190 strncpy((char *)param->lmd, fname, param->lumlen);
2191 rc = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO,
2192 (void *)param->lmd);
2198 if (errno == ENODATA) {
2199 if (!param->obduuid && !param->quiet)
2200 llapi_err(LLAPI_MSG_ERROR,
2201 "%s has no stripe info", path);
2203 } else if (errno == ENOENT) {
2204 llapi_err(LLAPI_MSG_ERROR,
2205 "warning: %s: %s does not exist",
2206 __FUNCTION__, path);
2208 } else if (errno != EISDIR) {
2210 llapi_err(LLAPI_MSG_ERROR, "%s ioctl failed for %s.",
2211 d ? "LL_IOC_MDC_GETINFO" :
2212 "IOC_MDC_GETFILEINFO", path);
2217 st = ¶m->lmd->lmd_st;
2219 /* libc chown() will do extra check, and if the real owner is
2220 * the same as the ones to set, it won't fall into kernel, so
2221 * invoke syscall directly. */
2222 rc = syscall(SYS_chown, path, -1, -1);
2224 llapi_err(LLAPI_MSG_ERROR,"error: chown %s (%u,%u)", path);
2226 rc = chmod(path, st->st_mode);
2228 llapi_err(LLAPI_MSG_ERROR, "error: chmod %s (%hu)",
2234 int llapi_quotachown(char *path, int flag)
2236 struct find_param param;
2238 int ret = 0, len = strlen(path);
2240 if (len > PATH_MAX) {
2241 llapi_err(LLAPI_MSG_ERROR, "%s: Path name '%s' is too long",
2242 __FUNCTION__, path);
2246 buf = (char *)malloc(PATH_MAX + 1);
2250 memset(¶m, 0, sizeof(param));
2251 param.recursive = 1;
2255 ret = common_param_init(¶m);
2259 strncpy(buf, path, PATH_MAX + 1);
2260 ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_quotachown,
2261 NULL, ¶m, NULL);
2263 find_param_fini(¶m);
2271 #include <sys/wait.h>
2275 static int rmtacl_notify(int ops)
2279 int found = 0, fd, rc;
2281 fp = setmntent(MOUNTED, "r");
2283 perror("setmntent");
2288 mnt = getmntent(fp);
2292 if (!llapi_is_lustre_mnt(mnt))
2295 fd = open(mnt->mnt_dir, O_RDONLY | O_DIRECTORY);
2301 rc = ioctl(fd, LL_IOC_RMTACL, ops);
2313 static char *next_token(char *p, int div)
2319 while (*p && *p != ':' && !isspace(*p))
2322 while (*p == ':' || isspace(*p))
2325 return *p ? p : NULL;
2328 static int rmtacl_name2id(char *name, int is_user)
2333 if ((pw = getpwnam(name)) == NULL)
2336 return (int)(pw->pw_uid);
2340 if ((gr = getgrnam(name)) == NULL)
2343 return (int)(gr->gr_gid);
2347 static int isodigit(int c)
2349 return (c >= '0' && c <= '7') ? 1 : 0;
2353 * Whether the name is just digits string (uid/gid) already or not.
2358 static int str_is_id(char *str)
2365 if (*str == 'x' || *str == 'X') { /* for Hex. */
2366 if (!isxdigit(*(++str)))
2369 while (isxdigit(*(++str)));
2370 } else if (isodigit(*str)) { /* for Oct. */
2371 while (isodigit(*(++str)));
2373 } else if (isdigit(*str)) { /* for Dec. */
2374 while (isdigit(*(++str)));
2377 return (*str == 0) ? 1 : 0;
2387 #define RMTACL_OPTNAME(name) name, sizeof(name) - 1
2389 static rmtacl_name_t rmtacl_namelist[] = {
2390 { RMTACL_OPTNAME("user:"), 1, 0 },
2391 { RMTACL_OPTNAME("group:"), 0, 0 },
2392 { RMTACL_OPTNAME("default:user:"), 1, 0 },
2393 { RMTACL_OPTNAME("default:group:"), 0, 0 },
2394 /* for --tabular option */
2395 { RMTACL_OPTNAME("user"), 1, 1 },
2396 { RMTACL_OPTNAME("group"), 0, 1 },
2400 static int rgetfacl_output(char *str)
2402 char *start = NULL, *end = NULL;
2403 int is_user = 0, n, id;
2410 for (rn = rmtacl_namelist; rn->name; rn++) {
2411 if(strncmp(str, rn->name, rn->length) == 0) {
2412 if (!rn->next_token)
2413 start = str + rn->length;
2415 start = next_token(str + rn->length, 0);
2416 is_user = rn->is_user;
2421 end = next_token(start, 1);
2422 if (end == NULL || start == end) {
2423 n = printf("%s", str);
2429 id = rmtacl_name2id(start, is_user);
2430 if (id == INVALID_ID) {
2431 if (str_is_id(start)) {
2433 n = printf("%s", str);
2436 } else if ((id == NOBODY_UID && is_user) ||
2437 (id == NOBODY_GID && !is_user)) {
2439 n = printf("%s", str);
2443 n = printf("%s%d%s", str, id, end);
2448 static int child_status(int status)
2450 return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
2453 static int do_rmtacl(int argc, char *argv[], int ops, int (output_func)(char *))
2466 if ((pid = fork()) < 0) {
2472 /* child process redirects its output. */
2475 if (dup2(fd[1], 1) < 0) {
2486 status = rmtacl_notify(ops);
2490 exit(execvp(argv[0], argv));
2493 /* the following is parent process */
2494 if ((fp = fdopen(fd[0], "r")) == NULL) {
2501 while (fgets(buf, PIPE_BUF, fp) != NULL) {
2502 if (output_func(buf) < 0)
2503 fprintf(stderr, "WARNING: unexpected error!\n[%s]\n",
2509 if (waitpid(pid, &status, 0) < 0) {
2514 return child_status(status);
2517 int llapi_lsetfacl(int argc, char *argv[])
2519 return do_rmtacl(argc, argv, RMT_LSETFACL, NULL);
2522 int llapi_lgetfacl(int argc, char *argv[])
2524 return do_rmtacl(argc, argv, RMT_LGETFACL, NULL);
2527 int llapi_rsetfacl(int argc, char *argv[])
2529 return do_rmtacl(argc, argv, RMT_RSETFACL, NULL);
2532 int llapi_rgetfacl(int argc, char *argv[])
2534 return do_rmtacl(argc, argv, RMT_RGETFACL, rgetfacl_output);
2537 int llapi_cp(int argc, char *argv[])
2541 rc = rmtacl_notify(RMT_RSETFACL);
2545 exit(execvp(argv[0], argv));
2548 int llapi_ls(int argc, char *argv[])
2552 rc = rmtacl_notify(RMT_LGETFACL);
2556 exit(execvp(argv[0], argv));
2559 /* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed.
2560 * format must have %s%s, buf must be > 16
2562 static int get_mdtname(char *name, char *format, char *buf)
2564 char suffix[]="-MDT0000";
2565 int len = strlen(name);
2567 if ((len > 5) && (strncmp(name + len - 5, "_UUID", 5) == 0)) {
2568 name[len - 5] = '\0';
2573 if ((len <= 16) && strncmp(name + len - 8, "-MDT", 4) == 0) {
2576 /* Not enough room to add suffix */
2577 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2578 "MDT name too long |%s|", name);
2583 return sprintf(buf, format, name, suffix);
2586 /****** Changelog API ********/
2587 #define CHANGELOG_PRIV_MAGIC 0xCA8E1080
2588 struct changelog_private {
2594 /** Start reading from a changelog
2595 * @param priv Opaque private control structure
2596 * @param flags Start flags (e.g. follow)
2597 * @param device Report changes recorded on this MDT
2598 * @param startrec Report changes beginning with this record number
2600 int llapi_changelog_start(void **priv, int flags, const char *device,
2603 struct changelog_private *cp;
2608 if (device[0] == '/')
2609 rc = get_root_path(WANT_FSNAME, mdtname, NULL, (char *)device);
2611 strncpy(mdtname, device, sizeof(mdtname));
2613 /* Use either the mdd changelog (preferred) or a client mdc changelog */
2614 if (get_mdtname(mdtname,
2615 "/proc/fs/lustre/md[cd]/%s%s{,-mdc-*}/changelog",
2618 rc = first_match(path, path);
2622 if ((fd = open(path, O_RDONLY)) < 0) {
2623 llapi_err(LLAPI_MSG_ERROR, "error: can't open |%s|\n", path);
2627 rc = lseek(fd, (off_t)startrec, SEEK_SET);
2629 llapi_err(LLAPI_MSG_ERROR, "can't seek rc=%d\n", rc);
2633 cp = malloc(sizeof(*cp));
2639 cp->magic = CHANGELOG_PRIV_MAGIC;
2647 /** Finish reading from a changelog */
2648 int llapi_changelog_fini(void **priv)
2650 struct changelog_private *cp = (struct changelog_private *)*priv;
2652 if (!cp || (cp->magic != CHANGELOG_PRIV_MAGIC))
2661 static int pollwait(int fd) {
2662 struct pollfd pfds[1];
2666 pfds[0].events = POLLIN;
2667 rc = poll(pfds, 1, -1);
2668 return rc < 0 ? -errno : rc;
2671 /** Read the next changelog entry
2672 * @param priv Opaque private control structure
2673 * @param rech Changelog record handle; record will be allocated here
2674 * @return 0 valid message received; rec is set
2678 int llapi_changelog_recv(void *priv, struct changelog_rec **rech)
2680 struct changelog_private *cp = (struct changelog_private *)priv;
2681 struct changelog_rec rec, *recp;
2684 if (!cp || (cp->magic != CHANGELOG_PRIV_MAGIC))
2690 /* Read in the rec to get the namelen */
2691 rc = read(cp->fd, &rec, sizeof(rec));
2695 if (cp->flags && CHANGELOG_FLAG_FOLLOW) {
2696 rc = pollwait(cp->fd);
2704 recp = malloc(sizeof(rec) + rec.cr_namelen);
2707 memcpy(recp, &rec, sizeof(rec));
2708 rc = read(cp->fd, recp->cr_name, rec.cr_namelen);
2711 llapi_err(LLAPI_MSG_ERROR, "Can't read entire filename");
2719 /** Release the changelog record when done with it. */
2720 int llapi_changelog_free(struct changelog_rec **rech)
2728 int llapi_changelog_clear(const char *mdtname, const char *idstr,
2731 struct ioc_changelog_clear data;
2734 int id, fd, index, rc;
2737 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2738 "can't purge negative records\n");
2742 id = strtol(idstr + strlen(CHANGELOG_USER_PREFIX), NULL, 10);
2743 if ((id == 0) || (strncmp(idstr, CHANGELOG_USER_PREFIX,
2744 strlen(CHANGELOG_USER_PREFIX)) != 0)) {
2745 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2746 "expecting id of the form '"CHANGELOG_USER_PREFIX
2747 "<num>'; got '%s'\n", idstr);
2751 /* Take path, fsname, or MDTNAME. Assume MDT0000 in the former cases */
2752 if (mdtname[0] == '/') {
2754 fd = open(mdtname, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
2755 rc = fd < 0 ? -errno : 0;
2757 if (get_mdtname((char *)mdtname, "%s%s", fsname) < 0)
2759 ptr = fsname + strlen(fsname) - 8;
2761 index = strtol(ptr + 4, NULL, 10);
2762 rc = get_root_path(WANT_FD, fsname, &fd, NULL);
2765 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2766 "Can't open %s: %d\n", mdtname, rc);
2770 data.icc_mdtindex = index;
2772 data.icc_recno = endrec;
2773 rc = ioctl(fd, OBD_IOC_CHANGELOG_CLEAR, &data);
2775 llapi_err(LLAPI_MSG_ERROR, "ioctl err %d", rc);
2781 int llapi_fid2path(const char *device, const char *fidstr, char *buf,
2782 int buflen, long long *recno, int *linkno)
2784 char path[PATH_MAX];
2786 struct getinfo_fid2path *gf;
2789 while (*fidstr == '[')
2792 sscanf(fidstr, SFID, RFID(&fid));
2793 if (!fid_is_sane(&fid)) {
2794 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2795 "bad FID format [%s], should be "DFID"\n",
2796 fidstr, (__u64)1, 2, 0);
2800 /* Take path or fsname */
2801 if (device[0] == '/') {
2802 strcpy(path, device);
2804 rc = get_root_path(WANT_PATH, (char *)device, NULL, path);
2808 sprintf(path, "%s/%s/fid/%s", path, dot_lustre_name, fidstr);
2809 fd = open(path, O_RDONLY | O_NONBLOCK);
2813 gf = malloc(sizeof(*gf) + buflen);
2815 gf->gf_recno = *recno;
2816 gf->gf_linkno = *linkno;
2817 gf->gf_pathlen = buflen;
2818 rc = ioctl(fd, OBD_IOC_FID2PATH, gf);
2820 llapi_err(LLAPI_MSG_ERROR, "ioctl err %d", rc);
2822 memcpy(buf, gf->gf_path, gf->gf_pathlen);
2823 *recno = gf->gf_recno;
2824 *linkno = gf->gf_linkno;
2832 int llapi_path2fid(const char *path, lustre_fid *fid)
2836 fd = open(path, O_RDONLY);
2840 rc = ioctl(fd, LL_IOC_PATH2FID, fid);
2846 /****** HSM Copytool API ********/
2847 #define CT_PRIV_MAGIC 0xC0BE2001
2848 struct copytool_private {
2851 int archive_num_count;
2852 int archive_nums[0];
2855 #include <libcfs/libcfs.h>
2857 /** Register a copytool
2858 * @param priv Opaque private control structure
2859 * @param flags Open flags, currently unused (e.g. O_NONBLOCK)
2860 * @param archive_nums Which archive numbers this copytool is responsible for
2862 int llapi_copytool_start(void **priv, int flags, int archive_num_count,
2865 struct copytool_private *ct;
2868 if (archive_num_count > 0 && archive_nums == NULL) {
2869 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2870 "NULL archive numbers");
2874 ct = malloc(sizeof(*ct) +
2875 archive_num_count * sizeof(ct->archive_nums[0]));
2879 ct->magic = CT_PRIV_MAGIC;
2880 ct->archive_num_count = archive_num_count;
2881 if (ct->archive_num_count > 0)
2882 memcpy(ct->archive_nums, archive_nums, archive_num_count *
2883 sizeof(ct->archive_nums[0]));
2885 rc = libcfs_ulnl_start(&ct->lnl, LNL_GRP_HSM);
2897 /** Deregister a copytool */
2898 int llapi_copytool_fini(void **priv)
2900 struct copytool_private *ct = (struct copytool_private *)*priv;
2902 if (!ct || (ct->magic != CT_PRIV_MAGIC))
2905 libcfs_ulnl_stop(&ct->lnl);
2911 /** Wait for the next hsm_action_list
2912 * @param priv Opaque private control structure
2913 * @param halh Action list handle, will be allocated here
2914 * @param msgsize Number of bytes in the message, will be set here
2915 * @return 0 valid message received; halh and msgsize are set
2918 int llapi_copytool_recv(void *priv, struct hsm_action_list **halh, int *msgsize)
2920 struct copytool_private *ct = (struct copytool_private *)priv;
2921 struct lnl_hdr *lnlh;
2922 struct hsm_action_list *hal;
2925 if (!ct || (ct->magic != CT_PRIV_MAGIC))
2927 if (halh == NULL || msgsize == NULL)
2930 rc = libcfs_ulnl_msg_get(&ct->lnl, HAL_MAXSIZE,
2931 LNL_TRANSPORT_HSM, &lnlh);
2935 /* Handle generic messages */
2936 if (lnlh->lnl_transport == LNL_TRANSPORT_GENERIC &&
2937 lnlh->lnl_msgtype == LNL_MSG_SHUTDOWN) {
2942 if (lnlh->lnl_transport != LNL_TRANSPORT_HSM ||
2943 lnlh->lnl_msgtype != HMT_ACTION_LIST) {
2944 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
2945 "Unknown HSM message type %d:%d\n",
2946 lnlh->lnl_transport, lnlh->lnl_msgtype);
2951 /* Our message is an hsm_action_list */
2953 hal = (struct hsm_action_list *)(lnlh + 1);
2955 /* Check that we have registered for this archive # */
2956 for (rc = 0; rc < ct->archive_num_count; rc++) {
2957 if (hal->hal_archive_num == ct->archive_nums[rc])
2960 if (rc >= ct->archive_num_count) {
2961 CDEBUG(D_INFO, "This copytool does not service archive #%d, "
2962 "ignoring this request.\n", hal->hal_archive_num);
2968 *msgsize = lnlh->lnl_msglen - sizeof(*lnlh);
2972 libcfs_ulnl_msg_free(&lnlh);
2978 /** Release the action list when done with it. */
2979 int llapi_copytool_free(struct hsm_action_list **hal)
2982 struct lnl_hdr *lnlh = (struct lnl_hdr *)*hal - 1;
2983 libcfs_ulnl_msg_free(&lnlh);