4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/utils/liblustreapi.c
33 * Author: Peter J. Braam <braam@clusterfs.com>
34 * Author: Phil Schwan <phil@clusterfs.com>
35 * Author: Robert Read <rread@clusterfs.com>
49 #include <sys/ioctl.h>
56 #include <sys/statfs.h>
57 #include <sys/syscall.h>
59 #include <sys/types.h>
60 #include <sys/xattr.h>
61 #include <sys/sysmacros.h>
64 #include <libgen.h> /* for dirname() */
65 #include <linux/limits.h>
66 #ifdef HAVE_LINUX_UNISTD_H
67 #include <linux/unistd.h>
75 #include <libcfs/util/ioctl.h>
76 #include <libcfs/util/param.h>
77 #include <libcfs/util/string.h>
78 #include <linux/lnet/lnetctl.h>
79 #include <lustre/lustreapi.h>
80 #include <linux/lustre/lustre_ostid.h>
81 #include <linux/lustre/lustre_ioctl.h>
82 #include "lustreapi_internal.h"
85 static int llapi_msg_level = LLAPI_MSG_MAX;
86 const char *liblustreapi_cmd;
88 struct lustre_foreign_type lu_foreign_types[] = {
89 {.lft_type = LU_FOREIGN_TYPE_NONE, .lft_name = "none"},
90 {.lft_type = LU_FOREIGN_TYPE_SYMLINK, .lft_name = "symlink"},
91 /* must be the last element */
92 {.lft_type = LU_FOREIGN_TYPE_UNKNOWN, .lft_name = NULL}
93 /* array max dimension must be <= UINT32_MAX */
96 void llapi_msg_set_level(int level)
98 /* ensure level is in the good range */
99 if (level < LLAPI_MSG_OFF)
100 llapi_msg_level = LLAPI_MSG_OFF;
101 else if (level > LLAPI_MSG_MAX)
102 llapi_msg_level = LLAPI_MSG_MAX;
104 llapi_msg_level = level;
107 int llapi_msg_get_level(void)
109 return llapi_msg_level;
112 void llapi_set_command_name(const char *cmd)
114 liblustreapi_cmd = cmd;
117 void llapi_clear_command_name(void)
119 liblustreapi_cmd = NULL;
122 static void error_callback_default(enum llapi_message_level level, int err,
123 const char *fmt, va_list ap)
125 bool has_nl = strchr(fmt, '\n') != NULL;
127 if (liblustreapi_cmd != NULL)
128 fprintf(stderr, "%s %s: ", program_invocation_short_name,
131 fprintf(stderr, "%s: ", program_invocation_short_name);
134 if (level & LLAPI_MSG_NO_ERRNO) {
135 vfprintf(stderr, fmt, ap);
137 fprintf(stderr, "\n");
142 * Remove trailing linefeed so error string can be appended.
143 * @fmt is a const string, so we can't modify it directly.
145 if (has_nl && (newfmt = strdup(fmt)))
146 *strrchr(newfmt, '\n') = '\0';
148 newfmt = (char *)fmt;
150 vfprintf(stderr, newfmt, ap);
153 fprintf(stderr, ": %s (%d)\n", strerror(err), err);
157 static void info_callback_default(enum llapi_message_level level, int err,
158 const char *fmt, va_list ap)
161 if (liblustreapi_cmd != NULL) {
162 fprintf(stdout, "%s %s: ",
163 program_invocation_short_name,
166 fprintf(stdout, "%s: ", program_invocation_short_name);
169 vfprintf(stdout, fmt, ap);
172 static llapi_log_callback_t llapi_error_callback = error_callback_default;
173 static llapi_log_callback_t llapi_info_callback = info_callback_default;
176 /* llapi_error will preserve errno */
177 void llapi_error(enum llapi_message_level level, int err, const char *fmt, ...)
180 int tmp_errno = errno;
182 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
186 llapi_error_callback(level, abs(err), fmt, args);
191 /* llapi_printf will preserve errno */
192 void llapi_printf(enum llapi_message_level level, const char *fmt, ...)
195 int tmp_errno = errno;
197 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
201 llapi_info_callback(level, 0, fmt, args);
207 * Set a custom error logging function. Passing in NULL will reset the logging
208 * callback to its default value.
210 * This function returns the value of the old callback.
212 llapi_log_callback_t llapi_error_callback_set(llapi_log_callback_t cb)
214 llapi_log_callback_t old = llapi_error_callback;
217 llapi_error_callback = cb;
219 llapi_error_callback = error_callback_default;
225 * Set a custom info logging function. Passing in NULL will reset the logging
226 * callback to its default value.
228 * This function returns the value of the old callback.
230 llapi_log_callback_t llapi_info_callback_set(llapi_log_callback_t cb)
232 llapi_log_callback_t old = llapi_info_callback;
235 llapi_info_callback = cb;
237 llapi_info_callback = info_callback_default;
243 * size_units is to be initialized (or zeroed) by caller.
245 int llapi_parse_size(const char *optarg, unsigned long long *size,
246 unsigned long long *size_units, int bytes_spec)
249 char *argbuf = (char *)optarg;
250 unsigned long long frac = 0, frac_d = 1;
252 if (strncmp(optarg, "-", 1) == 0)
255 if (*size_units == 0)
258 *size = strtoull(argbuf, &end, 0);
259 if (end != NULL && *end == '.') {
263 frac = strtoull(argbuf, &end, 10);
264 /* count decimal places */
265 for (i = 0; i < (end - argbuf); i++)
270 if ((*end == 'b') && *(end + 1) == '\0' &&
271 (*size & (~0ULL << (64 - 9))) == 0 &&
273 *size_units = 1 << 9;
274 } else if ((*end == 'b') &&
275 *(end + 1) == '\0' &&
278 } else if ((*end == 'k' || *end == 'K') &&
279 *(end + 1) == '\0' &&
280 (*size & (~0ULL << (64 - 10))) == 0) {
281 *size_units = 1 << 10;
282 } else if ((*end == 'm' || *end == 'M') &&
283 *(end + 1) == '\0' &&
284 (*size & (~0ULL << (64 - 20))) == 0) {
285 *size_units = 1 << 20;
286 } else if ((*end == 'g' || *end == 'G') &&
287 *(end + 1) == '\0' &&
288 (*size & (~0ULL << (64 - 30))) == 0) {
289 *size_units = 1 << 30;
290 } else if ((*end == 't' || *end == 'T') &&
291 *(end + 1) == '\0' &&
292 (*size & (~0ULL << (64 - 40))) == 0) {
293 *size_units = 1ULL << 40;
294 } else if ((*end == 'p' || *end == 'P') &&
295 *(end + 1) == '\0' &&
296 (*size & (~0ULL << (64 - 50))) == 0) {
297 *size_units = 1ULL << 50;
298 } else if ((*end == 'e' || *end == 'E') &&
299 *(end + 1) == '\0' &&
300 (*size & (~0ULL << (64 - 60))) == 0) {
301 *size_units = 1ULL << 60;
306 *size = *size * *size_units + frac * *size_units / frac_d;
311 int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len)
313 struct obd_ioctl_data *overlay;
316 data->ioc_len = obd_ioctl_packlen(data);
317 data->ioc_version = OBD_IOCTL_VERSION;
319 if (*pbuf != NULL && data->ioc_len > max_len) {
320 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
321 "pbuf = %p, ioc_len = %u, max_len = %d",
322 *pbuf, data->ioc_len, max_len);
327 *pbuf = malloc(data->ioc_len);
332 overlay = (struct obd_ioctl_data *)*pbuf;
333 memcpy(*pbuf, data, sizeof(*data));
335 ptr = overlay->ioc_bulk;
336 if (data->ioc_inlbuf1) {
337 memcpy(ptr, data->ioc_inlbuf1, data->ioc_inllen1);
338 ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
341 if (data->ioc_inlbuf2) {
342 memcpy(ptr, data->ioc_inlbuf2, data->ioc_inllen2);
343 ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
346 if (data->ioc_inlbuf3) {
347 memcpy(ptr, data->ioc_inlbuf3, data->ioc_inllen3);
348 ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
351 if (data->ioc_inlbuf4) {
352 memcpy(ptr, data->ioc_inlbuf4, data->ioc_inllen4);
353 ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
359 int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
361 struct obd_ioctl_data *overlay;
367 overlay = (struct obd_ioctl_data *)pbuf;
369 /* Preserve the caller's buffer pointers */
370 overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
371 overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
372 overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
373 overlay->ioc_inlbuf4 = data->ioc_inlbuf4;
375 memcpy(data, pbuf, sizeof(*data));
377 ptr = overlay->ioc_bulk;
378 if (data->ioc_inlbuf1) {
379 memcpy(data->ioc_inlbuf1, ptr, data->ioc_inllen1);
380 ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
383 if (data->ioc_inlbuf2) {
384 memcpy(data->ioc_inlbuf2, ptr, data->ioc_inllen2);
385 ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
388 if (data->ioc_inlbuf3) {
389 memcpy(data->ioc_inlbuf3, ptr, data->ioc_inllen3);
390 ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
393 if (data->ioc_inlbuf4) {
394 memcpy(data->ioc_inlbuf4, ptr, data->ioc_inllen4);
395 ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
401 /* XXX: llapi_xxx() functions return negative values upon failure */
403 int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname)
405 char ostname[MAX_OBD_NAME + 64];
406 char *pool_name = pname;
410 * The current policy is that the pool does not have to exist at the
411 * setstripe time, see sanity-pfl/-flr tests.
412 * If this logic will change, re-enable it.
414 * if (pname && strlen(pname) == 0)
418 snprintf(ostname, sizeof(ostname), "%s-OST%04x_UUID",
420 rc = llapi_search_ost(fsname, pool_name, ostname);
425 llapi_error(LLAPI_MSG_ERROR, rc,
426 "%s: cannot find OST %s in %s", __func__, ostname,
427 pool_name != NULL ? "pool" : "system");
435 * Verify the setstripe parameters before using.
436 * This is a pair method for comp_args_to_layout()/llapi_layout_sanity_cb()
437 * when just 1 component or a non-PFL layout is given.
439 * \param[in] param stripe parameters
440 * \param[in] pool_name pool name
441 * \param[in] fsname lustre FS name
444 * < 0, error code on failre
446 static int llapi_stripe_param_verify(const struct llapi_stripe_param *param,
451 static int page_size;
454 if (page_size == 0) {
456 * 64 KB is the largest common page size (on ia64/PPC/ARM),
457 * but check the local page size just in case. The page_size
458 * will not change for the lifetime of this process at least.
460 page_size = LOV_MIN_STRIPE_SIZE;
461 if (getpagesize() > page_size) {
462 page_size = getpagesize();
463 llapi_err_noerrno(LLAPI_MSG_WARN,
464 "warning: page size (%u) larger than expected (%u)",
465 page_size, LOV_MIN_STRIPE_SIZE);
468 if (!llapi_stripe_size_is_aligned(param->lsp_stripe_size)) {
470 llapi_error(LLAPI_MSG_ERROR, rc,
471 "error: bad stripe_size %llu, must be an even multiple of %d bytes",
472 param->lsp_stripe_size, page_size);
475 if (!llapi_stripe_index_is_valid(param->lsp_stripe_offset)) {
477 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
478 param->lsp_stripe_offset);
481 if (llapi_stripe_size_is_too_big(param->lsp_stripe_size)) {
483 llapi_error(LLAPI_MSG_ERROR, rc,
484 "error: stripe size '%llu' over 4GB limit",
485 param->lsp_stripe_size);
489 count = param->lsp_stripe_count;
490 if (param->lsp_stripe_pattern == LOV_PATTERN_MDT) {
492 llapi_error(LLAPI_MSG_ERROR, rc,
493 "Invalid pattern: %d, must be specified with -E\n",
494 param->lsp_stripe_pattern);
497 if (!llapi_stripe_count_is_valid(count)) {
499 llapi_error(LLAPI_MSG_ERROR, rc,
500 "Invalid stripe count %d\n", count);
505 /* Make sure we have a good pool */
506 if (*pool_name != NULL) {
507 if (!llapi_pool_name_is_valid(pool_name, fsname)) {
509 llapi_error(LLAPI_MSG_ERROR, rc,
510 "Pool '%s' is not on filesystem '%s'",
515 /* Make sure the pool exists and is non-empty */
516 rc = llapi_search_ost(fsname, *pool_name, NULL);
518 char *err = rc == 0 ? "has no OSTs" : "does not exist";
521 llapi_error(LLAPI_MSG_ERROR, rc, "pool '%s.%s' %s",
522 fsname, *pool_name, err);
528 /* sanity check of target list */
529 if (param->lsp_is_specific) {
533 for (i = 0; i < count; i++) {
534 rc = llapi_layout_search_ost(param->lsp_osts[i],
539 /* Make sure stripe offset is in OST list. */
540 if (param->lsp_osts[i] == param->lsp_stripe_offset)
545 llapi_error(LLAPI_MSG_ERROR, rc,
546 "%s: stripe offset '%d' is not in the target list",
547 __func__, param->lsp_stripe_offset);
550 } else if (param->lsp_stripe_offset != -1) {
551 rc = llapi_layout_search_ost(param->lsp_stripe_offset,
561 int llapi_dir_stripe_limit_check(int stripe_offset, int stripe_count,
566 if (!llapi_dir_stripe_index_is_valid(stripe_offset)) {
568 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
572 if (!llapi_dir_stripe_count_is_valid(stripe_count)) {
574 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
579 if (!llapi_dir_hash_type_is_valid(hash_type)) {
581 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad hash type %d",
589 * Trim a trailing newline from a string, if it exists.
591 int llapi_chomp_string(char *buf)
607 * Wrapper to grab parameter settings for lov.*-clilov-*.* values
609 static int get_param_lov(const char *path, const char *param,
610 char *buf, size_t buf_size)
612 struct obd_uuid uuid;
615 rc = llapi_file_get_lov_uuid(path, &uuid);
619 return get_lustre_param_value("lov", uuid.uuid, FILTER_BY_EXACT, param,
624 * Wrapper to grab parameter settings for lmv.*-clilov-*.* values
626 static int get_param_lmv(const char *path, const char *param,
627 char *buf, size_t buf_size)
629 struct obd_uuid uuid;
632 rc = llapi_file_get_lmv_uuid(path, &uuid);
636 return get_lustre_param_value("lmv", uuid.uuid, FILTER_BY_EXACT, param,
640 static int get_mds_md_size(const char *path)
642 int md_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
645 * Rather than open the file and do the ioctl to get the
646 * instance name and close the file and search for the param
647 * file and open the param file and read the param file and
648 * parse the value and close the param file, let's just return
649 * a large enough value. It's 2020, RAM is cheap and this is
653 if (md_size < XATTR_SIZE_MAX)
654 md_size = XATTR_SIZE_MAX;
659 int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize)
661 return get_param_lmv(path, "uuid", buf, bufsize);
665 * Open a Lustre file.
667 * \param name the name of the file to be opened
668 * \param flags access mode, see flags in open(2)
669 * \param mode permission of the file if it is created, see mode in open(2)
670 * \param param stripe pattern of the newly created file
672 * \retval file descriptor of opened file
673 * \retval negative errno on failure
675 int llapi_file_open_param(const char *name, int flags, mode_t mode,
676 const struct llapi_stripe_param *param)
678 char fsname[MAX_OBD_NAME + 1] = { 0 };
679 struct lov_user_md *lum = NULL;
680 char *pool_name = param->lsp_pool;
684 /* Make sure we are on a Lustre file system */
685 rc = llapi_search_fsname(name, fsname);
687 llapi_error(LLAPI_MSG_ERROR, rc,
688 "'%s' is not on a Lustre filesystem",
693 /* Check if the stripe pattern is sane. */
694 rc = llapi_stripe_param_verify(param, &pool_name, fsname);
698 if (param->lsp_is_specific)
699 lum_size = lov_user_md_size(param->lsp_stripe_count,
700 LOV_USER_MAGIC_SPECIFIC);
702 lum_size = sizeof(struct lov_user_md_v3);
704 lum_size = sizeof(*lum);
706 lum = calloc(1, lum_size);
711 fd = open(name, flags | O_LOV_DELAY_CREATE, mode);
713 if (errno == EISDIR && !(flags & O_DIRECTORY)) {
714 flags = O_DIRECTORY | O_RDONLY;
721 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
726 /* Initialize IOCTL striping pattern structure */
727 lum->lmm_magic = LOV_USER_MAGIC_V1;
728 lum->lmm_pattern = param->lsp_stripe_pattern;
729 lum->lmm_stripe_size = param->lsp_stripe_size;
730 lum->lmm_stripe_count = param->lsp_stripe_count;
731 lum->lmm_stripe_offset = param->lsp_stripe_offset;
732 if (pool_name != NULL) {
733 struct lov_user_md_v3 *lumv3 = (void *)lum;
735 lumv3->lmm_magic = LOV_USER_MAGIC_V3;
736 strncpy(lumv3->lmm_pool_name, pool_name, LOV_MAXPOOLNAME);
738 if (param->lsp_is_specific) {
739 struct lov_user_md_v3 *lumv3 = (void *)lum;
742 lumv3->lmm_magic = LOV_USER_MAGIC_SPECIFIC;
743 if (pool_name == NULL) {
745 * LOV_USER_MAGIC_SPECIFIC uses v3 format plus specified
746 * OST list, therefore if pool is not specified we have
747 * to pack a null pool name for placeholder.
749 memset(lumv3->lmm_pool_name, 0, LOV_MAXPOOLNAME);
752 for (i = 0; i < param->lsp_stripe_count; i++)
753 lumv3->lmm_objects[i].l_ost_idx = param->lsp_osts[i];
756 if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, lum) != 0) {
757 char errmsg[512] = "stripe already set";
760 if (errno != EEXIST && errno != EALREADY)
761 strncpy(errmsg, strerror(errno), sizeof(errmsg) - 1);
762 if (rc == -EREMOTEIO)
763 snprintf(errmsg, sizeof(errmsg),
764 "inactive OST among your specified %d OST(s)",
765 param->lsp_stripe_count);
767 llapi_err_noerrno(LLAPI_MSG_ERROR,
768 "setstripe error for '%s': %s", name, errmsg);
779 int llapi_file_open_pool(const char *name, int flags, int mode,
780 unsigned long long stripe_size, int stripe_offset,
781 int stripe_count, int stripe_pattern, char *pool_name)
783 const struct llapi_stripe_param param = {
784 .lsp_stripe_size = stripe_size,
785 .lsp_stripe_count = stripe_count,
786 .lsp_stripe_pattern = stripe_pattern,
787 .lsp_stripe_offset = stripe_offset,
788 .lsp_pool = pool_name
790 return llapi_file_open_param(name, flags, mode, ¶m);
793 int llapi_file_open(const char *name, int flags, int mode,
794 unsigned long long stripe_size, int stripe_offset,
795 int stripe_count, int stripe_pattern)
797 return llapi_file_open_pool(name, flags, mode, stripe_size,
798 stripe_offset, stripe_count,
799 stripe_pattern, NULL);
802 int llapi_file_create_foreign(const char *name, mode_t mode, __u32 type,
803 __u32 flags, char *foreign_lov)
806 struct lov_foreign_md *lfm;
809 if (foreign_lov == NULL) {
811 llapi_error(LLAPI_MSG_ERROR, rc,
812 "foreign LOV EA content must be provided");
816 len = strlen(foreign_lov);
817 if (len > XATTR_SIZE_MAX - offsetof(struct lov_foreign_md, lfm_value) ||
820 llapi_error(LLAPI_MSG_ERROR, rc,
821 "foreign LOV EA size %zu (must be 0 < len < %zu)",
822 len, XATTR_SIZE_MAX -
823 offsetof(struct lov_foreign_md, lfm_value));
827 lfm = malloc(len + offsetof(struct lov_foreign_md, lfm_value));
830 llapi_error(LLAPI_MSG_ERROR, rc,
831 "failed to allocate lov_foreign_md");
835 fd = open(name, O_WRONLY|O_CREAT|O_LOV_DELAY_CREATE, mode);
838 llapi_error(LLAPI_MSG_ERROR, fd, "open '%s' failed", name);
842 lfm->lfm_magic = LOV_USER_MAGIC_FOREIGN;
843 lfm->lfm_length = len;
844 lfm->lfm_type = type;
845 lfm->lfm_flags = flags;
846 memcpy(lfm->lfm_value, foreign_lov, len);
848 if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, lfm) != 0) {
849 char *errmsg = "stripe already set";
853 errmsg = "not on a Lustre filesystem";
854 else if (errno == EEXIST || errno == EALREADY)
855 errmsg = "stripe already set";
857 errmsg = strerror(errno);
859 llapi_err_noerrno(LLAPI_MSG_ERROR,
860 "setstripe error for '%s': %s", name, errmsg);
876 int llapi_file_create(const char *name, unsigned long long stripe_size,
877 int stripe_offset, int stripe_count, int stripe_pattern)
881 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
882 stripe_offset, stripe_count, stripe_pattern,
891 int llapi_file_create_pool(const char *name, unsigned long long stripe_size,
892 int stripe_offset, int stripe_count,
893 int stripe_pattern, char *pool_name)
897 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
898 stripe_offset, stripe_count, stripe_pattern,
907 static int verify_dir_param(const char *name,
908 const struct llapi_stripe_param *param)
910 char fsname[MAX_OBD_NAME + 1] = { 0 };
911 char *pool_name = param->lsp_pool;
914 /* Make sure we are on a Lustre file system */
915 rc = llapi_search_fsname(name, fsname);
917 llapi_error(LLAPI_MSG_ERROR, rc,
918 "'%s' is not on a Lustre filesystem",
923 /* Check if the stripe pattern is sane. */
924 rc = llapi_dir_stripe_limit_check(param->lsp_stripe_offset,
925 param->lsp_stripe_count,
926 param->lsp_stripe_pattern);
930 /* Make sure we have a good pool */
931 if (pool_name != NULL) {
933 * in case user gives the full pool name <fsname>.<poolname>,
936 char *ptr = strchr(pool_name, '.');
940 if (strcmp(pool_name, fsname) != 0) {
942 llapi_err_noerrno(LLAPI_MSG_ERROR,
943 "Pool '%s' is not on filesystem '%s'",
950 /* Make sure the pool exists and is non-empty */
951 rc = llapi_search_tgt(fsname, pool_name, NULL, true);
953 char *err = rc == 0 ? "has no OSTs" : "does not exist";
955 llapi_err_noerrno(LLAPI_MSG_ERROR, "pool '%s.%s' %s",
956 fsname, pool_name, err);
961 /* sanity check of target list */
962 if (param->lsp_is_specific) {
963 char mdtname[MAX_OBD_NAME + 64];
967 for (i = 0; i < param->lsp_stripe_count; i++) {
968 snprintf(mdtname, sizeof(mdtname), "%s-MDT%04x_UUID",
969 fsname, param->lsp_tgts[i]);
970 rc = llapi_search_tgt(fsname, pool_name, mdtname, true);
975 llapi_error(LLAPI_MSG_ERROR, rc,
976 "%s: cannot find MDT %s in %s",
983 /* Make sure stripe offset is in MDT list. */
984 if (param->lsp_tgts[i] == param->lsp_stripe_offset)
988 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
989 "%s: stripe offset '%d' is not in the target list",
990 __func__, param->lsp_stripe_offset);
998 static inline void param2lmu(struct lmv_user_md *lmu,
999 const struct llapi_stripe_param *param)
1001 lmu->lum_magic = param->lsp_is_specific ? LMV_USER_MAGIC_SPECIFIC :
1003 lmu->lum_stripe_count = param->lsp_stripe_count;
1004 lmu->lum_stripe_offset = param->lsp_stripe_offset;
1005 lmu->lum_hash_type = param->lsp_stripe_pattern;
1006 lmu->lum_max_inherit = param->lsp_max_inherit;
1007 lmu->lum_max_inherit_rr = param->lsp_max_inherit_rr;
1008 if (param->lsp_pool != NULL)
1009 strncpy(lmu->lum_pool_name, param->lsp_pool, LOV_MAXPOOLNAME);
1010 if (param->lsp_is_specific) {
1013 for (i = 0; i < param->lsp_stripe_count; i++)
1014 lmu->lum_objects[i].lum_mds = param->lsp_tgts[i];
1018 int llapi_dir_set_default_lmv(const char *name,
1019 const struct llapi_stripe_param *param)
1021 struct lmv_user_md lmu = { 0 };
1025 rc = verify_dir_param(name, param);
1029 /* TODO: default lmv doesn't support specific targets yet */
1030 if (param->lsp_is_specific)
1033 param2lmu(&lmu, param);
1035 fd = open(name, O_DIRECTORY | O_RDONLY);
1038 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
1042 rc = ioctl(fd, LL_IOC_LMV_SET_DEFAULT_STRIPE, &lmu);
1044 char *errmsg = "stripe already set";
1047 if (errno != EEXIST && errno != EALREADY)
1048 errmsg = strerror(errno);
1050 llapi_err_noerrno(LLAPI_MSG_ERROR,
1051 "default dirstripe error on '%s': %s",
1058 int llapi_dir_set_default_lmv_stripe(const char *name, int stripe_offset,
1059 int stripe_count, int stripe_pattern,
1060 const char *pool_name)
1062 const struct llapi_stripe_param param = {
1063 .lsp_stripe_count = stripe_count,
1064 .lsp_stripe_offset = stripe_offset,
1065 .lsp_stripe_pattern = stripe_pattern,
1066 .lsp_pool = (char *)pool_name
1069 return llapi_dir_set_default_lmv(name, ¶m);
1073 * Create a Lustre directory.
1075 * \param name the name of the directory to be created
1076 * \param mode permission of the file if it is created, see mode in open(2)
1077 * \param param stripe pattern of the newly created directory
1079 * \retval 0 on success
1080 * \retval negative errno on failure
1082 int llapi_dir_create(const char *name, mode_t mode,
1083 const struct llapi_stripe_param *param)
1085 struct lmv_user_md *lmu = NULL;
1087 struct obd_ioctl_data data = { 0 };
1090 char *dirpath = NULL;
1091 char *namepath = NULL;
1096 rc = verify_dir_param(name, param);
1100 lmu_size = lmv_user_md_size(param->lsp_stripe_count,
1101 param->lsp_is_specific ?
1102 LMV_USER_MAGIC_SPECIFIC :
1105 lmu = calloc(1, lmu_size);
1109 dirpath = strdup(name);
1115 namepath = strdup(name);
1122 param2lmu(lmu, param);
1124 filename = basename(namepath);
1125 dir = dirname(dirpath);
1127 data.ioc_inlbuf1 = (char *)filename;
1128 data.ioc_inllen1 = strlen(filename) + 1;
1129 data.ioc_inlbuf2 = (char *)lmu;
1130 data.ioc_inllen2 = lmu_size;
1131 data.ioc_type = mode;
1132 if (param->lsp_is_create)
1133 /* borrow obdo1.o_flags to store this flag */
1134 data.ioc_obdo1.o_flags = OBD_FL_OBDMDEXISTS;
1135 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1137 llapi_error(LLAPI_MSG_ERROR, rc,
1138 "error: LL_IOC_LMV_SETSTRIPE pack failed '%s'.",
1143 fd = open(dir, O_DIRECTORY | O_RDONLY);
1146 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
1150 if (ioctl(fd, LL_IOC_LMV_SETSTRIPE, buf)) {
1151 char *errmsg = "stripe already set";
1154 if (errno != EEXIST && errno != EALREADY)
1155 errmsg = strerror(errno);
1157 llapi_err_noerrno(LLAPI_MSG_ERROR,
1158 "dirstripe error on '%s': %s", name, errmsg);
1169 * Create a foreign directory.
1171 * \param name the name of the directory to be created
1172 * \param mode permission of the file if it is created, see mode in open(2)
1173 * \param type foreign type to be set in LMV EA
1174 * \param flags foreign flags to be set in LMV EA
1175 * \param value foreign pattern to be set in LMV EA
1177 * \retval 0 on success
1178 * \retval negative errno on failure
1180 int llapi_dir_create_foreign(const char *name, mode_t mode, __u32 type,
1181 __u32 flags, const char *value)
1183 struct lmv_foreign_md *lfm = NULL;
1184 size_t lfm_size, len;
1185 struct obd_ioctl_data data = { 0 };
1188 char *dirpath = NULL;
1189 char *namepath = NULL;
1194 len = strlen(value);
1195 if (len > XATTR_SIZE_MAX - offsetof(struct lmv_foreign_md, lfm_value) ||
1198 llapi_error(LLAPI_MSG_ERROR, rc,
1199 "invalid LOV EA length %zu (must be 0 < len < %zu)",
1200 len, XATTR_SIZE_MAX -
1201 offsetof(struct lmv_foreign_md, lfm_value));
1204 lfm_size = len + offsetof(struct lmv_foreign_md, lfm_value);
1205 lfm = calloc(1, lfm_size);
1209 dirpath = strdup(name);
1215 namepath = strdup(name);
1222 lfm->lfm_magic = LMV_MAGIC_FOREIGN;
1223 lfm->lfm_length = len;
1224 lfm->lfm_type = type;
1225 lfm->lfm_flags = flags;
1226 memcpy(lfm->lfm_value, value, len);
1228 filename = basename(namepath);
1229 dir = dirname(dirpath);
1231 data.ioc_inlbuf1 = (char *)filename;
1232 data.ioc_inllen1 = strlen(filename) + 1;
1233 data.ioc_inlbuf2 = (char *)lfm;
1234 data.ioc_inllen2 = lfm_size;
1235 data.ioc_type = mode;
1236 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1238 llapi_error(LLAPI_MSG_ERROR, rc,
1239 "error: LL_IOC_LMV_SETSTRIPE pack failed '%s'.",
1244 fd = open(dir, O_DIRECTORY | O_RDONLY);
1247 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
1251 if (ioctl(fd, LL_IOC_LMV_SETSTRIPE, buf)) {
1252 char *errmsg = "stripe already set";
1255 if (errno != EEXIST && errno != EALREADY)
1256 errmsg = strerror(errno);
1258 llapi_err_noerrno(LLAPI_MSG_ERROR,
1259 "dirstripe error on '%s': %s", name, errmsg);
1269 int llapi_dir_create_pool(const char *name, int mode, int stripe_offset,
1270 int stripe_count, int stripe_pattern,
1271 const char *pool_name)
1273 const struct llapi_stripe_param param = {
1274 .lsp_stripe_count = stripe_count,
1275 .lsp_stripe_offset = stripe_offset,
1276 .lsp_stripe_pattern = stripe_pattern,
1277 .lsp_pool = (char *)pool_name
1280 return llapi_dir_create(name, mode, ¶m);
1284 * Find the fsname, the full path, and/or an open fd.
1285 * Either the fsname or path must not be NULL
1287 int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
1290 char buf[PATH_MAX], mntdir[PATH_MAX];
1291 char *ptr, *ptr_end;
1293 int idx = 0, mntlen = 0, fd;
1295 int fsnamelen, mountlen;
1297 /* get the mount point */
1298 fp = setmntent(PROC_MOUNTS, "r");
1301 llapi_error(LLAPI_MSG_ERROR, rc,
1302 "cannot retrieve filesystem mount point");
1306 if (getmntent_r(fp, &mnt, buf, sizeof(buf)) == NULL)
1309 if (!llapi_is_lustre_mnt(&mnt))
1312 if ((want & WANT_INDEX) && (idx++ != index))
1315 mntlen = strlen(mnt.mnt_dir);
1316 ptr = strchr(mnt.mnt_fsname, '/');
1317 while (ptr && *ptr == '/')
1320 * thanks to the call to llapi_is_lustre_mnt() above,
1321 * we are sure that mnt.mnt_fsname contains ":/",
1322 * so ptr should never be NULL
1327 while (*ptr_end != '/' && *ptr_end != '\0')
1330 /* Check the fsname for a match, if given */
1331 mountlen = ptr_end - ptr;
1332 if (!(want & WANT_FSNAME) && fsname != NULL &&
1333 (fsnamelen = strlen(fsname)) > 0 &&
1334 (fsnamelen != mountlen ||
1335 (strncmp(ptr, fsname, mountlen) != 0)))
1338 /* If the path isn't set return the first one we find */
1339 if (path == NULL || strlen(path) == 0) {
1340 strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
1341 mntdir[sizeof(mntdir) - 1] = '\0';
1342 if ((want & WANT_FSNAME) && fsname != NULL) {
1343 strncpy(fsname, ptr, mountlen);
1344 fsname[mountlen] = '\0';
1348 /* Otherwise find the longest matching path */
1349 } else if ((strlen(path) >= mntlen) &&
1350 (strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
1351 /* check the path format */
1352 if (strlen(path) > mntlen && path[mntlen] != '/')
1354 strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
1355 mntdir[sizeof(mntdir) - 1] = '\0';
1356 if ((want & WANT_FSNAME) && fsname != NULL) {
1357 strncpy(fsname, ptr, mountlen);
1358 fsname[mountlen] = '\0';
1368 if ((want & WANT_PATH) && path != NULL) {
1369 strncpy(path, mntdir, mntlen);
1370 path[mntlen] = '\0';
1372 if (want & WANT_FD) {
1373 fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
1376 llapi_error(LLAPI_MSG_ERROR, rc,
1377 "cannot open '%s'", mntdir);
1383 } else if (want & WANT_ERROR)
1384 llapi_err_noerrno(LLAPI_MSG_ERROR,
1385 "'%s' not on a mounted Lustre filesystem",
1386 (want & WANT_PATH) ? fsname : path);
1391 * search lustre mounts
1393 * Calling this function will return to the user the mount point, mntdir, and
1394 * the file system name, fsname, if the user passed a buffer to this routine.
1396 * The user inputs are pathname and index. If the pathname is supplied then
1397 * the value of the index will be ignored. The pathname will return data if
1398 * the pathname is located on a lustre mount. Index is used to pick which
1399 * mount point you want in the case of multiple mounted lustre file systems.
1400 * See function lfs_osts in lfs.c for an example of the index use.
1402 int llapi_search_mounts(const char *pathname, int index, char *mntdir,
1405 int want = WANT_PATH, idx = -1;
1407 if (!pathname || pathname[0] == '\0') {
1411 strcpy(mntdir, pathname);
1415 want |= WANT_FSNAME;
1416 return get_root_path(want, fsname, NULL, mntdir, idx);
1419 /* Given a path, find the corresponding Lustre fsname */
1420 int llapi_search_fsname(const char *pathname, char *fsname)
1425 path = realpath(pathname, NULL);
1427 char tmp[PATH_MAX - 1];
1433 if (pathname[0] != '/') {
1435 * Need an absolute path, but realpath() only works for
1436 * pathnames that actually exist. We go through the
1437 * extra hurdle of dirname(getcwd() + pathname) in
1438 * case the relative pathname contains ".." in it.
1440 char realpath[PATH_MAX - 1];
1442 if (getcwd(realpath, sizeof(realpath) - 2) == NULL) {
1444 llapi_error(LLAPI_MSG_ERROR, rc,
1445 "cannot get current working directory");
1449 rc = snprintf(tmp, sizeof(tmp), "%s/", realpath);
1450 if (rc >= sizeof(tmp)) {
1452 llapi_error(LLAPI_MSG_ERROR, rc,
1453 "invalid parent path '%s'",
1459 rc = snprintf(buf, sizeof(buf), "%s%s", tmp, pathname);
1460 if (rc >= sizeof(buf)) {
1462 llapi_error(LLAPI_MSG_ERROR, rc,
1463 "invalid path '%s'", pathname);
1466 path = realpath(buf, NULL);
1468 ptr = strrchr(buf, '/');
1470 llapi_error(LLAPI_MSG_ERROR |
1471 LLAPI_MSG_NO_ERRNO, 0,
1472 "cannot resolve path '%s'",
1477 path = realpath(buf, NULL);
1480 llapi_error(LLAPI_MSG_ERROR, rc,
1481 "cannot resolve path '%s'",
1487 rc = get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL, path, -1);
1492 int llapi_search_rootpath(char *pathname, const char *fsname)
1495 * pathname can be used as an argument by get_root_path(),
1496 * clear it for safety
1499 return get_root_path(WANT_PATH, (char *)fsname, NULL, pathname, -1);
1503 * Get the list of pool members.
1504 * \param poolname string of format \<fsname\>.\<poolname\>
1505 * \param members caller-allocated array of char*
1506 * \param list_size size of the members array
1507 * \param buffer caller-allocated buffer for storing OST names
1508 * \param buffer_size size of the buffer
1510 * \return number of members retrieved for this pool
1511 * \retval -error failure
1513 int llapi_get_poolmembers(const char *poolname, char **members,
1514 int list_size, char *buffer, int buffer_size)
1516 char fsname[PATH_MAX];
1525 /* name is FSNAME.POOLNAME */
1526 if (strlen(poolname) >= sizeof(fsname))
1529 snprintf(fsname, sizeof(fsname), "%s", poolname);
1530 pool = strchr(fsname, '.');
1537 rc = poolpath(&pathname, fsname, NULL);
1539 llapi_error(LLAPI_MSG_ERROR, rc,
1540 "Lustre filesystem '%s' not found",
1545 llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
1546 rc = snprintf(buf, sizeof(buf), "%s/%s", pathname.gl_pathv[0], pool);
1547 cfs_free_param_data(&pathname);
1548 if (rc >= sizeof(buf))
1550 fd = fopen(buf, "r");
1553 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open %s", buf);
1558 while (fgets(buf, sizeof(buf), fd) != NULL) {
1559 if (nb_entries >= list_size) {
1563 buf[sizeof(buf) - 1] = '\0';
1565 tmp = strchr(buf, '\n');
1568 if (used + strlen(buf) + 1 > buffer_size) {
1573 strcpy(buffer + used, buf);
1574 members[nb_entries] = buffer + used;
1575 used += strlen(buf) + 1;
1585 * Get the list of pools in a filesystem.
1586 * \param name filesystem name or path
1587 * \param poollist caller-allocated array of char*
1588 * \param list_size size of the poollist array
1589 * \param buffer caller-allocated buffer for storing pool names
1590 * \param buffer_size size of the buffer
1592 * \return number of pools retrieved for this filesystem
1593 * \retval -error failure
1595 int llapi_get_poollist(const char *name, char **poollist, int list_size,
1596 char *buffer, int buffer_size)
1602 struct dirent *pool;
1604 unsigned int nb_entries = 0;
1605 unsigned int used = 0;
1608 /* initialize output array */
1609 for (i = 0; i < list_size; i++)
1612 /* is name a pathname ? */
1613 ptr = strchr(name, '/');
1615 char fsname_buf[MAXNAMLEN];
1617 /* We will need fsname for printing later */
1618 rc = llapi_getname(name, fsname_buf, sizeof(fsname_buf));
1622 ptr = strrchr(fsname_buf, '-');
1626 fsname = strdup(fsname_buf);
1630 /* name is FSNAME */
1631 fsname = strdup(name);
1636 rc = poolpath(&pathname, fsname, NULL);
1638 llapi_error(LLAPI_MSG_ERROR, rc,
1639 "Lustre filesystem '%s' not found", name);
1643 dir = opendir(pathname.gl_pathv[0]);
1646 llapi_error(LLAPI_MSG_ERROR, rc,
1647 "Could not open pool list for '%s'",
1654 pool = readdir(dir);
1660 /* ignore . and .. */
1661 if (!strcmp(pool->d_name, ".") || !strcmp(pool->d_name, ".."))
1664 /* check output bounds */
1665 if (nb_entries >= list_size) {
1667 goto free_dir_no_msg;
1670 /* +2 for '.' and final '\0' */
1671 if (used + strlen(pool->d_name) + strlen(fsname) + 2
1674 goto free_dir_no_msg;
1677 sprintf(buffer + used, "%s.%s", fsname, pool->d_name);
1678 poollist[nb_entries] = buffer + used;
1679 used += strlen(pool->d_name) + strlen(fsname) + 2;
1685 llapi_error(LLAPI_MSG_ERROR, rc,
1686 "Error reading pool list for '%s'", name);
1688 llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
1693 cfs_free_param_data(&pathname);
1696 return rc != 0 ? rc : nb_entries;
1699 /* wrapper for lfs.c and obd.c */
1700 int llapi_poollist(const char *name)
1703 * list of pool names (assume that pool count is smaller
1706 char **list, *buffer = NULL, *fsname = (char *)name;
1707 char *poolname = NULL, *tmp = NULL, data[16];
1708 enum param_filter type = FILTER_BY_PATH;
1709 int obdcount, bufsize, rc, nb, i;
1714 if (name[0] != '/') {
1715 fsname = strdup(name);
1719 poolname = strchr(fsname, '.');
1722 type = FILTER_BY_FS_NAME;
1725 rc = get_lustre_param_value("lov", fsname, type, "numobd",
1726 data, sizeof(data));
1729 obdcount = atoi(data);
1732 * Allocate space for each fsname-OST0000_UUID, 1 per OST,
1733 * and also an array to store the pointers for all that
1737 bufsize = sizeof(struct obd_uuid) * obdcount;
1738 buffer = realloc(tmp, bufsize + sizeof(*list) * obdcount);
1739 if (buffer == NULL) {
1743 list = (char **) (buffer + bufsize);
1746 /* name is a path or fsname */
1747 nb = llapi_get_poollist(name, list, obdcount,
1750 /* name is a pool name (<fsname>.<poolname>) */
1751 nb = llapi_get_poolmembers(name, list, obdcount,
1755 if (nb == -EOVERFLOW) {
1758 goto retry_get_pools;
1761 for (i = 0; i < nb; i++)
1762 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", list[i]);
1763 rc = (nb < 0 ? nb : 0);
1767 if (fsname != NULL && type == FILTER_BY_FS_NAME)
1772 typedef int (semantic_func_t)(char *path, int p, int *d,
1773 void *data, struct dirent64 *de);
1775 #define OBD_NOT_FOUND (-1)
1777 static void find_param_fini(struct find_param *param)
1779 if (param->fp_migrate)
1782 if (param->fp_obd_indexes) {
1783 free(param->fp_obd_indexes);
1784 param->fp_obd_indexes = NULL;
1787 if (param->fp_lmd) {
1788 free(param->fp_lmd);
1789 param->fp_lmd = NULL;
1792 if (param->fp_lmv_md) {
1793 free(param->fp_lmv_md);
1794 param->fp_lmv_md = NULL;
1798 static int common_param_init(struct find_param *param, char *path)
1800 int lum_size = get_mds_md_size(path);
1805 /* migrate has fp_lmv_md initialized outside */
1806 if (param->fp_migrate)
1809 if (lum_size < PATH_MAX + 1)
1810 lum_size = PATH_MAX + 1;
1812 param->fp_lum_size = lum_size;
1813 param->fp_lmd = calloc(1, offsetof(typeof(*param->fp_lmd), lmd_lmm) +
1815 if (param->fp_lmd == NULL) {
1816 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1817 "error: allocate %zu bytes for layout failed",
1818 sizeof(lstat_t) + param->fp_lum_size);
1822 param->fp_lmv_stripe_count = 256;
1823 param->fp_lmv_md = calloc(1,
1824 lmv_user_md_size(param->fp_lmv_stripe_count,
1825 LMV_USER_MAGIC_SPECIFIC));
1826 if (param->fp_lmv_md == NULL) {
1827 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1828 "error: allocation of %d bytes for ioctl",
1829 lmv_user_md_size(param->fp_lmv_stripe_count,
1830 LMV_USER_MAGIC_SPECIFIC));
1831 find_param_fini(param);
1835 param->fp_got_uuids = 0;
1836 param->fp_obd_indexes = NULL;
1837 param->fp_obd_index = OBD_NOT_FOUND;
1838 param->fp_mdt_index = OBD_NOT_FOUND;
1842 static int cb_common_fini(char *path, int p, int *dp, void *data,
1843 struct dirent64 *de)
1845 struct find_param *param = data;
1851 /* set errno upon failure */
1852 static int open_parent(const char *path)
1858 path_copy = strdup(path);
1859 if (path_copy == NULL)
1862 parent_path = dirname(path_copy);
1863 parent = open(parent_path, O_RDONLY|O_NDELAY|O_DIRECTORY);
1869 static int cb_get_dirstripe(char *path, int *d, struct find_param *param)
1872 bool did_nofollow = false;
1875 param->fp_lmv_md->lum_stripe_count = param->fp_lmv_stripe_count;
1876 if (param->fp_get_default_lmv)
1877 param->fp_lmv_md->lum_magic = LMV_USER_MAGIC;
1879 param->fp_lmv_md->lum_magic = LMV_MAGIC_V1;
1881 ret = ioctl(*d, LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);
1883 /* if ENOTTY likely to be a fake symlink, so try again after
1884 * new open() with O_NOFOLLOW, but only once to prevent any
1885 * loop like for the path of a file/dir not on Lustre !!
1887 if (ret < 0 && errno == ENOTTY && !did_nofollow) {
1890 did_nofollow = true;
1891 fd = open(path, O_RDONLY | O_NOFOLLOW);
1893 /* restore original errno */
1898 /* close original fd and set new */
1901 ret2 = ioctl(fd, LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);
1902 if (ret2 < 0 && errno != E2BIG) {
1903 /* restore original errno */
1907 /* LMV is ok or need to handle E2BIG case now */
1911 if (errno == E2BIG && ret != 0) {
1915 /* if foreign LMV case, fake stripes number */
1916 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
1917 struct lmv_foreign_md *lfm;
1919 lfm = (struct lmv_foreign_md *)param->fp_lmv_md;
1920 if (lfm->lfm_length < XATTR_SIZE_MAX -
1921 offsetof(typeof(*lfm), lfm_value)) {
1922 uint32_t size = lfm->lfm_length +
1923 offsetof(typeof(*lfm), lfm_value);
1925 stripe_count = lmv_foreign_to_md_stripes(size);
1927 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
1928 "error: invalid %d foreign size returned from ioctl",
1933 stripe_count = param->fp_lmv_md->lum_stripe_count;
1935 if (stripe_count <= param->fp_lmv_stripe_count)
1938 free(param->fp_lmv_md);
1939 param->fp_lmv_stripe_count = stripe_count;
1940 lmv_size = lmv_user_md_size(stripe_count,
1941 LMV_USER_MAGIC_SPECIFIC);
1942 param->fp_lmv_md = malloc(lmv_size);
1943 if (param->fp_lmv_md == NULL) {
1944 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1945 "error: allocation of %d bytes for ioctl",
1946 lmv_user_md_size(param->fp_lmv_stripe_count,
1947 LMV_USER_MAGIC_SPECIFIC));
1955 static void convert_lmd_statx(struct lov_user_mds_data *lmd_v2, lstat_t *st,
1958 memset(&lmd_v2->lmd_stx, 0, sizeof(lmd_v2->lmd_stx));
1959 lmd_v2->lmd_stx.stx_blksize = st->st_blksize;
1960 lmd_v2->lmd_stx.stx_nlink = st->st_nlink;
1961 lmd_v2->lmd_stx.stx_uid = st->st_uid;
1962 lmd_v2->lmd_stx.stx_gid = st->st_gid;
1963 lmd_v2->lmd_stx.stx_mode = st->st_mode;
1964 lmd_v2->lmd_stx.stx_ino = st->st_ino;
1965 lmd_v2->lmd_stx.stx_size = st->st_size;
1966 lmd_v2->lmd_stx.stx_blocks = st->st_blocks;
1967 lmd_v2->lmd_stx.stx_atime.tv_sec = st->st_atime;
1968 lmd_v2->lmd_stx.stx_ctime.tv_sec = st->st_ctime;
1969 lmd_v2->lmd_stx.stx_mtime.tv_sec = st->st_mtime;
1970 lmd_v2->lmd_stx.stx_rdev_major = major(st->st_rdev);
1971 lmd_v2->lmd_stx.stx_rdev_minor = minor(st->st_rdev);
1972 lmd_v2->lmd_stx.stx_dev_major = major(st->st_dev);
1973 lmd_v2->lmd_stx.stx_dev_minor = minor(st->st_dev);
1974 lmd_v2->lmd_stx.stx_mask |= STATX_BASIC_STATS;
1976 lmd_v2->lmd_flags = 0;
1978 lmd_v2->lmd_flags |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
1980 lmd_v2->lmd_stx.stx_mask &= ~(STATX_SIZE | STATX_BLOCKS);
1981 if (lmd_v2->lmd_stx.stx_size)
1982 lmd_v2->lmd_flags |= OBD_MD_FLLAZYSIZE;
1983 if (lmd_v2->lmd_stx.stx_blocks)
1984 lmd_v2->lmd_flags |= OBD_MD_FLLAZYBLOCKS;
1986 lmd_v2->lmd_flags |= OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1987 OBD_MD_FLBLKSZ | OBD_MD_FLMODE | OBD_MD_FLTYPE |
1988 OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLNLINK |
1993 static int convert_lmdbuf_v1v2(void *lmdbuf, int lmdlen)
1995 struct lov_user_mds_data_v1 *lmd_v1 = lmdbuf;
1996 struct lov_user_mds_data *lmd_v2 = lmdbuf;
2000 size = lov_comp_md_size((struct lov_comp_md_v1 *)&lmd_v1->lmd_lmm);
2004 if (lmdlen < sizeof(lmd_v1->lmd_st) + size)
2007 st = lmd_v1->lmd_st;
2008 memmove(&lmd_v2->lmd_lmm, &lmd_v1->lmd_lmm,
2009 lmdlen - (&lmd_v2->lmd_lmm - &lmd_v1->lmd_lmm));
2010 convert_lmd_statx(lmd_v2, &st, false);
2011 lmd_v2->lmd_lmmsize = 0;
2012 lmd_v2->lmd_padding = 0;
2017 int get_lmd_info_fd(const char *path, int parent_fd, int dir_fd,
2018 void *lmdbuf, int lmdlen, enum get_lmd_info_type type)
2020 struct lov_user_mds_data *lmd = lmdbuf;
2021 static bool use_old_ioctl;
2025 if (parent_fd < 0 && dir_fd < 0)
2027 if (type != GET_LMD_INFO && type != GET_LMD_STRIPE)
2032 * LL_IOC_MDC_GETINFO operates on the current directory inode
2033 * and returns struct lov_user_mds_data, while
2034 * LL_IOC_LOV_GETSTRIPE returns only struct lov_user_md.
2036 if (type == GET_LMD_INFO)
2037 cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_V1 :
2038 LL_IOC_MDC_GETINFO_V2;
2040 cmd = LL_IOC_LOV_GETSTRIPE;
2043 ret = ioctl(dir_fd, cmd, lmdbuf);
2044 if (ret < 0 && errno == ENOTTY &&
2045 cmd == LL_IOC_MDC_GETINFO_V2) {
2046 cmd = LL_IOC_MDC_GETINFO_V1;
2047 use_old_ioctl = true;
2051 if (cmd == LL_IOC_MDC_GETINFO_V1 && !ret)
2052 ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
2054 if (ret < 0 && errno == ENOTTY && type == GET_LMD_STRIPE) {
2057 /* retry ioctl() after new open() with O_NOFOLLOW
2058 * just in case it could be a fake symlink
2059 * need using a new open() as dir_fd is being closed
2063 dir_fd2 = open(path, O_RDONLY | O_NDELAY | O_NOFOLLOW);
2065 /* return original error */
2068 ret = ioctl(dir_fd2, cmd, lmdbuf);
2069 /* pass new errno or success back to caller */
2075 } else if (parent_fd >= 0) {
2076 const char *fname = strrchr(path, '/');
2079 * IOC_MDC_GETFILEINFO takes as input the filename (relative to
2080 * the parent directory) and returns struct lov_user_mds_data,
2081 * while IOC_MDC_GETFILESTRIPE returns only struct lov_user_md.
2083 * This avoids opening, locking, and closing each file on the
2084 * client if that is not needed. Multiple of these ioctl() can
2085 * be done on the parent dir with a single open for all
2086 * files in that directory, and it also doesn't pollute the
2087 * client dcache with millions of dentries when traversing
2088 * a large filesystem.
2090 fname = (fname == NULL ? path : fname + 1);
2092 ret = snprintf(lmdbuf, lmdlen, "%s", fname);
2095 else if (ret >= lmdlen || ret++ == 0)
2098 if (type == GET_LMD_INFO)
2099 cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_V1 :
2100 IOC_MDC_GETFILEINFO_V2;
2102 cmd = IOC_MDC_GETFILESTRIPE;
2105 ret = ioctl(parent_fd, cmd, lmdbuf);
2106 if (ret < 0 && errno == ENOTTY &&
2107 cmd == IOC_MDC_GETFILEINFO_V2) {
2108 cmd = IOC_MDC_GETFILEINFO_V1;
2109 use_old_ioctl = true;
2110 goto retry_getfileinfo;
2113 if (cmd == IOC_MDC_GETFILEINFO_V1 && !ret)
2114 ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
2118 if (ret && type == GET_LMD_INFO) {
2119 if (errno == ENOTTY) {
2123 * ioctl is not supported, it is not a lustre fs.
2124 * Do the regular lstat(2) instead.
2126 ret = lstat_f(path, &st);
2129 llapi_error(LLAPI_MSG_ERROR, ret,
2130 "error: %s: lstat failed for %s",
2134 convert_lmd_statx(lmd, &st, true);
2136 * It may be wrong to set use_old_ioctl with true as
2137 * the file is not a lustre fs. So reset it with false
2140 use_old_ioctl = false;
2141 } else if (errno == ENOENT) {
2143 llapi_error(LLAPI_MSG_WARN, ret,
2144 "warning: %s does not exist", path);
2145 } else if (errno != EISDIR && errno != ENODATA) {
2147 llapi_error(LLAPI_MSG_ERROR, ret,
2148 "%s ioctl failed for %s.",
2149 dir_fd >= 0 ? "LL_IOC_MDC_GETINFO" :
2150 "IOC_MDC_GETFILEINFO", path);
2157 static int llapi_semantic_traverse(char *path, int size, int parent,
2158 semantic_func_t sem_init,
2159 semantic_func_t sem_fini, void *data,
2160 struct dirent64 *de)
2162 struct find_param *param = (struct find_param *)data;
2163 struct dirent64 *dent;
2164 int len, ret, d, p = -1;
2170 d = open(path, O_RDONLY|O_NDELAY|O_DIRECTORY);
2171 /* if an invalid fake dir symlink, opendir() will return EINVAL
2172 * instead of ENOTDIR. If a valid but dangling faked or real file/dir
2173 * symlink ENOENT will be returned. For a valid/resolved fake or real
2174 * file symlink ENOTDIR will be returned as for a regular file.
2175 * opendir() will be successful for a valid and resolved fake or real
2176 * dir simlink or a regular dir.
2178 if (d == -1 && errno != ENOTDIR && errno != EINVAL && errno != ENOENT) {
2180 llapi_error(LLAPI_MSG_ERROR, ret, "%s: Failed to open '%s'",
2183 } else if (d == -1) {
2184 if (errno == ENOENT || errno == EINVAL) {
2185 int old_errno = errno;
2187 /* try to open with O_NOFOLLOW this will help
2188 * differentiate fake vs real symlinks
2189 * it is ok to not use O_DIRECTORY with O_RDONLY
2190 * and it will prevent the need to deal with ENOTDIR
2191 * error, instead of ELOOP, being returned by recent
2192 * kernels for real symlinks
2194 d = open(path, O_RDONLY|O_NDELAY|O_NOFOLLOW);
2195 /* if a dangling real symlink should return ELOOP, or
2196 * again ENOENT if really non-existing path, or E...??
2197 * So return original error. If success or ENOTDIR, path
2198 * is likely to be a fake dir/file symlink, so continue
2208 if (parent == -1 && d == -1) {
2209 /* Open the parent dir. */
2210 p = open_parent(path);
2216 } else { /* d != -1 */
2219 /* try to reopen dir with O_NOFOLLOW just in case of a foreign
2222 d2 = open(path, O_RDONLY|O_NDELAY|O_NOFOLLOW);
2227 /* continue with d */
2233 ret = sem_init(path, (parent != -1) ? parent : p, &d, data, de);
2243 /* ENOTDIR if fake symlink, do not consider it as an error */
2244 if (errno != ENOTDIR)
2245 llapi_error(LLAPI_MSG_ERROR, errno,
2246 "fdopendir() failed");
2253 while ((dent = readdir64(dir)) != NULL) {
2256 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
2260 if ((len + dent->d_reclen + 2) > size) {
2261 llapi_err_noerrno(LLAPI_MSG_ERROR,
2262 "error: %s: string buffer too small for %s",
2267 strcat(path, dent->d_name);
2269 if (dent->d_type == DT_UNKNOWN) {
2270 struct lov_user_mds_data *lmd = param->fp_lmd;
2272 rc = get_lmd_info_fd(path, d, -1, param->fp_lmd,
2273 param->fp_lum_size, GET_LMD_INFO);
2275 dent->d_type = IFTODT(lmd->lmd_stx.stx_mode);
2282 switch (dent->d_type) {
2284 llapi_err_noerrno(LLAPI_MSG_ERROR,
2285 "error: %s: '%s' is UNKNOWN type %d",
2286 __func__, dent->d_name, dent->d_type);
2289 rc = llapi_semantic_traverse(path, size, d, sem_init,
2290 sem_fini, data, dent);
2291 if (rc != 0 && ret == 0)
2297 rc = sem_init(path, d, NULL, data, dent);
2298 if (rc < 0 && ret == 0) {
2303 if (sem_fini && rc == 0)
2304 sem_fini(path, d, NULL, data, dent);
2312 sem_fini(path, parent, &d, data, de);
2325 static int param_callback(char *path, semantic_func_t sem_init,
2326 semantic_func_t sem_fini, struct find_param *param)
2328 int ret, len = strlen(path);
2331 if (len > PATH_MAX) {
2333 llapi_error(LLAPI_MSG_ERROR, ret,
2334 "Path name '%s' is too long", path);
2338 buf = (char *)malloc(2 * PATH_MAX);
2342 snprintf(buf, PATH_MAX + 1, "%s", path);
2343 ret = common_param_init(param, buf);
2347 param->fp_depth = 0;
2349 ret = llapi_semantic_traverse(buf, 2 * PATH_MAX, -1, sem_init,
2350 sem_fini, param, NULL);
2352 find_param_fini(param);
2354 return ret < 0 ? ret : 0;
2357 int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_name)
2361 rc = ioctl(fd, OBD_IOC_GETDTNAME, lov_name);
2362 if (rc && errno == ENOTTY)
2363 rc = ioctl(fd, OBD_IOC_GETNAME_OLD, lov_name);
2366 llapi_error(LLAPI_MSG_ERROR, rc, "cannot get lov name");
2372 int llapi_file_fget_lmv_uuid(int fd, struct obd_uuid *lov_name)
2376 rc = ioctl(fd, OBD_IOC_GETMDNAME, lov_name);
2379 llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get lmv name.");
2385 int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid)
2389 /* do not follow faked symlinks */
2390 fd = open(path, O_RDONLY | O_NONBLOCK | O_NOFOLLOW);
2392 /* real symlink should have failed with ELOOP so retry without
2393 * O_NOFOLLOW just in case
2395 fd = open(path, O_RDONLY | O_NONBLOCK);
2398 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'",
2404 rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
2410 int llapi_file_get_lmv_uuid(const char *path, struct obd_uuid *lov_uuid)
2414 fd = open(path, O_RDONLY | O_NONBLOCK);
2417 llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
2421 rc = llapi_file_fget_lmv_uuid(fd, lov_uuid);
2433 * If uuidp is NULL, return the number of available obd uuids.
2434 * If uuidp is non-NULL, then it will return the uuids of the obds. If
2435 * there are more OSTs than allocated to uuidp, then an error is returned with
2436 * the ost_count set to number of available obd uuids.
2438 static int llapi_get_target_uuids(int fd, struct obd_uuid *uuidp,
2439 int *ost_count, enum tgt_type type)
2441 char buf[PATH_MAX], format[32];
2442 int rc = 0, index = 0;
2443 struct obd_uuid name;
2447 /* Get the lov name */
2448 if (type == LOV_TYPE)
2449 rc = llapi_file_fget_lov_uuid(fd, &name);
2451 rc = llapi_file_fget_lmv_uuid(fd, &name);
2455 /* Now get the ost uuids */
2456 rc = get_lustre_param_path(type == LOV_TYPE ? "lov" : "lmv", name.uuid,
2457 FILTER_BY_EXACT, "target_obd", ¶m);
2461 fp = fopen(param.gl_pathv[0], "r");
2464 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
2469 snprintf(format, sizeof(format),
2470 "%%d: %%%zus", sizeof(uuidp[0].uuid) - 1);
2471 while (fgets(buf, sizeof(buf), fp) != NULL) {
2472 if (uuidp && (index < *ost_count)) {
2473 if (sscanf(buf, format, &index, uuidp[index].uuid) < 2)
2481 if (uuidp && (index > *ost_count))
2486 cfs_free_param_data(¶m);
2490 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
2492 return llapi_get_target_uuids(fd, uuidp, ost_count, LOV_TYPE);
2495 int llapi_get_obd_count(char *mnt, int *count, int is_mdt)
2500 root = open(mnt, O_RDONLY | O_DIRECTORY);
2503 llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
2508 rc = ioctl(root, LL_IOC_GETOBDCOUNT, count);
2517 * Check if user specified value matches a real uuid. Ignore _UUID,
2518 * -osc-4ba41334, other trailing gunk in comparison.
2519 * @param real_uuid ends in "_UUID"
2520 * @param search_uuid may or may not end in "_UUID"
2522 int llapi_uuid_match(char *real_uuid, char *search_uuid)
2524 int cmplen = strlen(real_uuid);
2525 int searchlen = strlen(search_uuid);
2527 if (cmplen > 5 && strcmp(real_uuid + cmplen - 5, "_UUID") == 0)
2529 if (searchlen > 5 && strcmp(search_uuid + searchlen - 5, "_UUID") == 0)
2533 * The UUIDs may legitimately be different lengths, if
2534 * the system was upgraded from an older version.
2536 if (cmplen != searchlen)
2539 return (strncmp(search_uuid, real_uuid, cmplen) == 0);
2543 * Here, param->fp_obd_uuid points to a single obduuid, the index of which is
2544 * returned in param->fp_obd_index
2546 static int setup_obd_uuid(int fd, char *dname, struct find_param *param)
2548 struct obd_uuid obd_uuid;
2555 if (param->fp_got_uuids)
2558 /* Get the lov/lmv name */
2559 if (param->fp_get_lmv)
2560 rc = llapi_file_fget_lmv_uuid(fd, &obd_uuid);
2562 rc = llapi_file_fget_lov_uuid(fd, &obd_uuid);
2564 if (rc != -ENOTTY) {
2565 llapi_error(LLAPI_MSG_ERROR, rc,
2566 "error: can't get %s name: %s",
2567 param->fp_get_lmv ? "lmv" : "lov",
2575 param->fp_got_uuids = 1;
2577 /* Now get the ost uuids */
2578 rc = get_lustre_param_path(param->fp_get_lmv ? "lmv" : "lov",
2579 obd_uuid.uuid, FILTER_BY_EXACT,
2580 "target_obd", ¶m_data);
2584 fp = fopen(param_data.gl_pathv[0], "r");
2587 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
2588 param_data.gl_pathv[0]);
2592 if (!param->fp_obd_uuid && !param->fp_quiet && !param->fp_obds_printed)
2593 llapi_printf(LLAPI_MSG_NORMAL, "%s:\n",
2594 param->fp_get_lmv ? "MDTS" : "OBDS");
2596 snprintf(format, sizeof(format),
2597 "%%d: %%%zus", sizeof(obd_uuid.uuid) - 1);
2598 while (fgets(buf, sizeof(buf), fp) != NULL) {
2601 if (sscanf(buf, format, &index, obd_uuid.uuid) < 2)
2604 if (param->fp_obd_uuid) {
2605 if (llapi_uuid_match(obd_uuid.uuid,
2606 param->fp_obd_uuid->uuid)) {
2607 param->fp_obd_index = index;
2610 } else if (!param->fp_quiet && !param->fp_obds_printed) {
2611 /* Print everything */
2612 llapi_printf(LLAPI_MSG_NORMAL, "%s", buf);
2615 param->fp_obds_printed = 1;
2619 if (param->fp_obd_uuid && (param->fp_obd_index == OBD_NOT_FOUND)) {
2620 llapi_err_noerrno(LLAPI_MSG_ERROR,
2621 "error: %s: unknown obduuid: %s",
2622 __func__, param->fp_obd_uuid->uuid);
2626 cfs_free_param_data(¶m_data);
2631 * In this case, param->fp_obd_uuid will be an array of obduuids and
2632 * obd index for all these obduuids will be returned in
2633 * param->fp_obd_indexes
2635 static int setup_indexes(int d, char *path, struct obd_uuid *obduuids,
2636 int num_obds, int **obdindexes, int *obdindex,
2639 int ret, obdcount, obd_valid = 0, obdnum;
2641 struct obd_uuid *uuids = NULL;
2645 if (type == LOV_TYPE)
2646 ret = get_param_lov(path, "numobd", buf, sizeof(buf));
2648 ret = get_param_lmv(path, "numobd", buf, sizeof(buf));
2652 obdcount = atoi(buf);
2653 uuids = malloc(obdcount * sizeof(struct obd_uuid));
2658 ret = llapi_get_target_uuids(d, uuids, &obdcount, type);
2660 if (ret == -EOVERFLOW) {
2661 struct obd_uuid *uuids_temp;
2663 uuids_temp = realloc(uuids, obdcount *
2664 sizeof(struct obd_uuid));
2665 if (uuids_temp != NULL) {
2667 goto retry_get_uuids;
2672 llapi_error(LLAPI_MSG_ERROR, ret, "cannot get ost uuid");
2676 indexes = malloc(num_obds * sizeof(*obdindex));
2677 if (indexes == NULL) {
2682 for (obdnum = 0; obdnum < num_obds; obdnum++) {
2685 /* The user may have specified a simple index */
2686 i = strtol(obduuids[obdnum].uuid, &end, 0);
2687 if (end && *end == '\0' && i < obdcount) {
2688 indexes[obdnum] = i;
2691 for (i = 0; i < obdcount; i++) {
2692 if (llapi_uuid_match(uuids[i].uuid,
2693 obduuids[obdnum].uuid)) {
2694 indexes[obdnum] = i;
2700 if (i >= obdcount) {
2701 indexes[obdnum] = OBD_NOT_FOUND;
2702 llapi_err_noerrno(LLAPI_MSG_ERROR,
2703 "invalid obduuid '%s'",
2704 obduuids[obdnum].uuid);
2710 *obdindex = OBD_NOT_FOUND;
2712 *obdindex = obd_valid;
2714 *obdindexes = indexes;
2722 static int setup_target_indexes(int d, char *path, struct find_param *param)
2726 if (param->fp_mdt_uuid) {
2727 ret = setup_indexes(d, path, param->fp_mdt_uuid,
2729 ¶m->fp_mdt_indexes,
2730 ¶m->fp_mdt_index, LMV_TYPE);
2735 if (param->fp_obd_uuid) {
2736 ret = setup_indexes(d, path, param->fp_obd_uuid,
2738 ¶m->fp_obd_indexes,
2739 ¶m->fp_obd_index, LOV_TYPE);
2744 param->fp_got_uuids = 1;
2749 int llapi_ostlist(char *path, struct find_param *param)
2754 fd = open(path, O_RDONLY | O_DIRECTORY);
2758 ret = setup_obd_uuid(fd, path, param);
2765 * Tries to determine the default stripe attributes for a given filesystem. The
2766 * filesystem to check should be specified by fsname, or will be determined
2769 static int sattr_get_defaults(const char *const fsname,
2770 unsigned int *scount,
2771 unsigned int *ssize,
2772 unsigned int *soffset)
2778 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2779 "stripecount", val, sizeof(val));
2782 *scount = atoi(val);
2786 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2787 "stripesize", val, sizeof(val));
2794 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2795 "stripeoffset", val, sizeof(val));
2798 *soffset = atoi(val);
2805 * Tries to gather the default stripe attributes for a given filesystem. If
2806 * the attributes can be determined, they are cached for easy retreival the
2807 * next time they are needed. Only a single filesystem's attributes are
2810 int sattr_cache_get_defaults(const char *const fsname,
2811 const char *const pathname, unsigned int *scount,
2812 unsigned int *ssize, unsigned int *soffset)
2815 char fsname[PATH_MAX + 1];
2816 unsigned int stripecount;
2817 unsigned int stripesize;
2818 unsigned int stripeoffset;
2824 char fsname_buf[PATH_MAX + 1];
2825 unsigned int tmp[3];
2827 if (fsname == NULL) {
2828 rc = llapi_search_fsname(pathname, fsname_buf);
2832 snprintf(fsname_buf, sizeof(fsname_buf), "%s", fsname);
2835 if (strncmp(fsname_buf, cache.fsname, sizeof(fsname_buf) - 1) != 0) {
2837 * Ensure all 3 sattrs (count, size, and offset) are
2838 * successfully retrieved and stored in tmp before writing to
2841 rc = sattr_get_defaults(fsname_buf, &tmp[0], &tmp[1], &tmp[2]);
2845 cache.stripecount = tmp[0];
2846 cache.stripesize = tmp[1];
2847 cache.stripeoffset = tmp[2];
2848 snprintf(cache.fsname, sizeof(cache.fsname), "%s", fsname_buf);
2852 *scount = cache.stripecount;
2854 *ssize = cache.stripesize;
2856 *soffset = cache.stripeoffset;
2861 static char *layout2name(__u32 layout_pattern)
2863 if (layout_pattern & LOV_PATTERN_F_RELEASED)
2865 else if (layout_pattern == LOV_PATTERN_MDT)
2867 else if (layout_pattern == LOV_PATTERN_RAID0)
2869 else if (layout_pattern ==
2870 (LOV_PATTERN_RAID0 | LOV_PATTERN_OVERSTRIPING))
2871 return "raid0,overstriped";
2876 enum lov_dump_flags {
2877 LDF_IS_DIR = 0x0001,
2878 LDF_IS_RAW = 0x0002,
2879 LDF_INDENT = 0x0004,
2880 LDF_SKIP_OBJS = 0x0008,
2882 LDF_EXTENSION = 0x0020,
2885 static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
2886 struct lov_user_ost_data_v1 *objects,
2887 enum llapi_layout_verbose verbose,
2888 int depth, char *pool_name,
2889 enum lov_dump_flags flags)
2891 bool is_dir = flags & LDF_IS_DIR;
2892 bool is_raw = flags & LDF_IS_RAW;
2893 bool indent = flags & LDF_INDENT;
2894 bool yaml = flags & LDF_YAML;
2895 bool skip_objs = flags & LDF_SKIP_OBJS;
2896 bool extension = flags & LDF_EXTENSION;
2897 char *prefix = is_dir ? "" : "lmm_";
2898 char *separator = "";
2899 char *space = indent ? " " : "";
2902 if (is_dir && lmm_oi_seq(&lum->lmm_oi) == FID_SEQ_LOV_DEFAULT) {
2903 lmm_oi_set_seq(&lum->lmm_oi, 0);
2904 if (!indent && (verbose & VERBOSE_DETAIL))
2905 llapi_printf(LLAPI_MSG_NORMAL, "%s(Default) ", space);
2908 if (!yaml && !indent && depth && path &&
2909 ((verbose != VERBOSE_OBJID) || !is_dir))
2910 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
2912 if ((verbose & VERBOSE_DETAIL) && !is_dir) {
2913 llapi_printf(LLAPI_MSG_NORMAL, "%s%smagic: 0x%08X\n",
2914 space, prefix, lum->lmm_magic);
2915 llapi_printf(LLAPI_MSG_NORMAL, "%s%sseq: %#jx\n",
2917 (uintmax_t)lmm_oi_seq(&lum->lmm_oi));
2918 llapi_printf(LLAPI_MSG_NORMAL, "%s%sobject_id: %#jx\n",
2920 (uintmax_t)lmm_oi_id(&lum->lmm_oi));
2923 if (verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) {
2928 if (verbose & ~VERBOSE_DFID)
2929 llapi_printf(LLAPI_MSG_NORMAL, "%slmm_fid: ",
2933 struct lu_fid dir_fid;
2935 rc = llapi_path2fid(path, &dir_fid);
2937 llapi_error(LLAPI_MSG_ERROR, rc,
2938 "Cannot determine directory fid.");
2940 seq = dir_fid.f_seq;
2941 oid = dir_fid.f_oid;
2942 ver = dir_fid.f_ver;
2945 * This needs a bit of hand-holding since old 1.x
2946 * lmm_oi have { oi.oi_id = mds_inum, oi.oi_seq = 0 }
2947 * and 2.x lmm_oi have { oi.oi_id = mds_oid,
2948 * oi.oi_seq = mds_seq } instead of a real FID.
2949 * Ideally the 2.x code would have stored this like a
2950 * FID with { oi_id = mds_seq, oi_seq = mds_oid } so
2951 * the ostid union lu_fid { f_seq = mds_seq,
2952 * f_oid = mds_oid } worked properly (especially since
2953 * IGIF FIDs use mds_inum as the FID SEQ), but
2954 * unfortunately that didn't happen.
2956 * Print it to look like an IGIF FID, even though the
2957 * fields are reversed on disk, so that it makes sense
2960 * Don't use ostid_id() and ostid_seq(), since they
2961 * assume the oi_fid fields are in the right order.
2962 * This is why there are separate lmm_oi_seq() and
2963 * lmm_oi_id() routines for this.
2965 * For newer layout types hopefully this will be a
2968 seq = lmm_oi_seq(&lum->lmm_oi) == 0 ?
2969 lmm_oi_id(&lum->lmm_oi) :
2970 lmm_oi_seq(&lum->lmm_oi);
2971 oid = lmm_oi_seq(&lum->lmm_oi) == 0 ?
2972 0 : (__u32)lmm_oi_id(&lum->lmm_oi);
2973 ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32);
2977 llapi_printf(LLAPI_MSG_NORMAL, DFID_NOBRACE"\n",
2978 (unsigned long long)seq, oid, ver);
2980 llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
2981 (unsigned long long)seq, oid, ver);
2984 if (verbose & VERBOSE_STRIPE_COUNT) {
2985 if (verbose & ~VERBOSE_STRIPE_COUNT)
2986 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_count: ",
2989 if (!is_raw && lum->lmm_stripe_count == 0 &&
2990 lov_pattern(lum->lmm_pattern) != LOV_PATTERN_MDT) {
2991 unsigned int scount;
2993 rc = sattr_cache_get_defaults(NULL, path,
2997 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3000 llapi_error(LLAPI_MSG_ERROR, rc,
3001 "Cannot determine default stripe count.");
3003 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3005 (__s16)lum->lmm_stripe_count);
3008 llapi_printf(LLAPI_MSG_NORMAL, "%hd",
3010 (__s16)lum->lmm_stripe_count);
3012 if (!yaml && is_dir)
3018 if (((verbose & VERBOSE_STRIPE_SIZE) && !extension) ||
3019 ((verbose & VERBOSE_EXT_SIZE) && extension)) {
3020 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3021 if (verbose & ~VERBOSE_EXT_SIZE && extension)
3022 llapi_printf(LLAPI_MSG_NORMAL, "%s%sextension_size: ",
3024 if (verbose & ~VERBOSE_STRIPE_SIZE && !extension)
3025 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_size: ",
3027 if (is_dir && !is_raw && lum->lmm_stripe_size == 0) {
3030 rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
3033 llapi_printf(LLAPI_MSG_NORMAL, "%u", ssize);
3035 llapi_error(LLAPI_MSG_ERROR, rc,
3036 "Cannot determine default stripe size.");
3038 /* Extension size is in KiB */
3039 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3041 (unsigned long long)(lum->lmm_stripe_size * SEL_UNIT_SIZE) :
3042 (unsigned long long)lum->lmm_stripe_size);
3044 if (!yaml && is_dir)
3050 if ((verbose & VERBOSE_PATTERN)) {
3051 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3052 if (verbose & ~VERBOSE_PATTERN)
3053 llapi_printf(LLAPI_MSG_NORMAL, "%s%spattern: ",
3055 if (lov_pattern_supported(lum->lmm_pattern))
3056 llapi_printf(LLAPI_MSG_NORMAL, "%s",
3057 layout2name(lum->lmm_pattern));
3059 llapi_printf(LLAPI_MSG_NORMAL, "%x", lum->lmm_pattern);
3060 separator = (!yaml && is_dir) ? " " : "\n";
3063 if ((verbose & VERBOSE_GENERATION) && !is_dir) {
3064 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3065 if (verbose & ~VERBOSE_GENERATION)
3066 llapi_printf(LLAPI_MSG_NORMAL, "%s%slayout_gen: ",
3068 llapi_printf(LLAPI_MSG_NORMAL, "%u",
3069 skip_objs ? 0 : (int)lum->lmm_layout_gen);
3073 if (verbose & VERBOSE_STRIPE_OFFSET) {
3074 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3075 if (verbose & ~VERBOSE_STRIPE_OFFSET)
3076 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_offset: ",
3078 if (is_dir || skip_objs)
3079 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3080 lum->lmm_stripe_offset ==
3081 (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
3082 lum->lmm_stripe_offset);
3083 else if (lov_pattern(lum->lmm_pattern) == LOV_PATTERN_MDT)
3084 llapi_printf(LLAPI_MSG_NORMAL, "0");
3086 llapi_printf(LLAPI_MSG_NORMAL, "%u",
3087 objects[0].l_ost_idx);
3088 if (!yaml && is_dir)
3094 if ((verbose & VERBOSE_POOL) && pool_name && (pool_name[0] != '\0')) {
3095 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3096 if (verbose & ~VERBOSE_POOL)
3097 llapi_printf(LLAPI_MSG_NORMAL, "%s%spool: ",
3099 llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name);
3100 if (!yaml && is_dir)
3106 if (strlen(separator) != 0)
3107 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3110 void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
3111 struct lov_user_ost_data_v1 *objects,
3112 char *path, int obdindex, int depth,
3113 enum llapi_layout_verbose verbose,
3114 enum lov_dump_flags flags)
3116 bool is_dir = flags & LDF_IS_DIR;
3117 bool indent = flags & LDF_INDENT;
3118 bool skip_objs = flags & LDF_SKIP_OBJS;
3119 bool yaml = flags & LDF_YAML;
3120 bool obdstripe = obdindex == OBD_NOT_FOUND;
3123 if (!obdstripe && !skip_objs) {
3124 for (i = 0; !is_dir && i < lum->lmm_stripe_count; i++) {
3125 if (obdindex == objects[i].l_ost_idx) {
3135 lov_dump_user_lmm_header(lum, path, objects, verbose, depth, pool_name,
3138 if (!is_dir && !skip_objs && (verbose & VERBOSE_OBJID) &&
3139 !(lum->lmm_pattern & LOV_PATTERN_F_RELEASED ||
3140 lov_pattern(lum->lmm_pattern) == LOV_PATTERN_MDT)) {
3141 char *space = " - ";
3144 llapi_printf(LLAPI_MSG_NORMAL,
3145 "%6slmm_objects:\n", " ");
3147 llapi_printf(LLAPI_MSG_NORMAL, "lmm_objects:\n");
3149 llapi_printf(LLAPI_MSG_NORMAL,
3150 "\tobdidx\t\t objid\t\t objid\t\t group\n");
3152 for (i = 0; i < lum->lmm_stripe_count; i++) {
3153 int idx = objects[i].l_ost_idx;
3154 long long oid = ostid_id(&objects[i].l_ost_oi);
3155 long long gr = ostid_seq(&objects[i].l_ost_oi);
3157 if (obdindex != OBD_NOT_FOUND && obdindex != idx)
3161 struct lu_fid fid = { 0 };
3163 ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
3164 llapi_printf(LLAPI_MSG_NORMAL,
3165 "%sl_ost_idx: %d\n", space, idx);
3166 llapi_printf(LLAPI_MSG_NORMAL,
3167 "%8sl_fid: "DFID_NOBRACE"\n",
3169 } else if (indent) {
3170 struct lu_fid fid = { 0 };
3172 ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
3173 llapi_printf(LLAPI_MSG_NORMAL,
3174 "%s%d: { l_ost_idx: %d, l_fid: "DFID" }\n",
3175 space, i, idx, PFID(&fid));
3179 sprintf(fmt, "%s%s%s\n",
3180 "\t%6u\t%14llu\t%#13llx\t",
3181 (fid_seq_is_rsvd(gr) ||
3182 fid_seq_is_mdt0(gr)) ?
3183 "%14llu" : "%#14llx", "%s");
3184 llapi_printf(LLAPI_MSG_NORMAL, fmt, idx, oid,
3186 obdindex == idx ? " *" : "");
3190 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3193 void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name,
3194 char *path, int obdindex, int depth,
3195 enum llapi_layout_verbose verbose,
3196 enum lov_dump_flags flags)
3198 struct lmv_user_mds_data *objects = lum->lum_objects;
3199 char *prefix = lum->lum_magic == LMV_USER_MAGIC ? "(Default)" : "";
3200 char *separator = "";
3201 bool yaml = flags & LDF_YAML;
3202 bool obdstripe = false;
3205 if (obdindex != OBD_NOT_FOUND) {
3206 if (lum->lum_stripe_count == 0) {
3207 if (obdindex == lum->lum_stripe_offset)
3210 for (i = 0; i < lum->lum_stripe_count; i++) {
3211 if (obdindex == objects[i].lum_mds) {
3212 llapi_printf(LLAPI_MSG_NORMAL,
3227 /* show all information default */
3229 if (lum->lum_magic == LMV_USER_MAGIC)
3230 verbose = VERBOSE_POOL | VERBOSE_STRIPE_COUNT |
3231 VERBOSE_STRIPE_OFFSET | VERBOSE_HASH_TYPE;
3233 verbose = VERBOSE_OBJID;
3236 if (depth && path && ((verbose != VERBOSE_OBJID)))
3237 llapi_printf(LLAPI_MSG_NORMAL, "%s%s\n", prefix, path);
3239 if (verbose & VERBOSE_STRIPE_COUNT) {
3240 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3241 if (verbose & ~VERBOSE_STRIPE_COUNT)
3242 llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_count: ");
3243 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3244 (int)lum->lum_stripe_count);
3245 if ((verbose & VERBOSE_STRIPE_OFFSET) && !yaml)
3251 if (verbose & VERBOSE_STRIPE_OFFSET) {
3252 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3253 if (verbose & ~VERBOSE_STRIPE_OFFSET)
3254 llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: ");
3255 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3256 (int)lum->lum_stripe_offset);
3257 if (verbose & VERBOSE_HASH_TYPE && !yaml)
3263 if (verbose & VERBOSE_HASH_TYPE) {
3264 unsigned int type = lum->lum_hash_type & LMV_HASH_TYPE_MASK;
3265 unsigned int flags = lum->lum_hash_type & ~LMV_HASH_TYPE_MASK;
3267 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3268 if (verbose & ~VERBOSE_HASH_TYPE)
3269 llapi_printf(LLAPI_MSG_NORMAL, "lmv_hash_type: ");
3270 if (type < LMV_HASH_TYPE_MAX)
3271 llapi_printf(LLAPI_MSG_NORMAL, "%s",
3272 mdt_hash_name[type]);
3274 llapi_printf(LLAPI_MSG_NORMAL, "%#x", type);
3276 if (flags & LMV_HASH_FLAG_MIGRATION)
3277 llapi_printf(LLAPI_MSG_NORMAL, ",migrating");
3278 if (flags & LMV_HASH_FLAG_BAD_TYPE)
3279 llapi_printf(LLAPI_MSG_NORMAL, ",bad_type");
3280 if (flags & LMV_HASH_FLAG_LOST_LMV)
3281 llapi_printf(LLAPI_MSG_NORMAL, ",lost_lmv");
3283 if (verbose & VERBOSE_HASH_TYPE && !yaml)
3289 if ((verbose & VERBOSE_INHERIT) && lum->lum_magic == LMV_USER_MAGIC) {
3290 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3291 if (verbose & ~VERBOSE_INHERIT)
3292 llapi_printf(LLAPI_MSG_NORMAL, "lmv_max_inherit: ");
3293 if (lum->lum_max_inherit == LMV_INHERIT_UNLIMITED)
3294 llapi_printf(LLAPI_MSG_NORMAL, "-1");
3295 else if (lum->lum_max_inherit == LMV_INHERIT_NONE)
3296 llapi_printf(LLAPI_MSG_NORMAL, "0");
3298 llapi_printf(LLAPI_MSG_NORMAL, "%hhu",
3299 lum->lum_max_inherit);
3300 if (verbose & VERBOSE_INHERIT && !yaml)
3306 if ((verbose & VERBOSE_INHERIT_RR) &&
3307 lum->lum_magic == LMV_USER_MAGIC &&
3308 lum->lum_stripe_offset == LMV_OFFSET_DEFAULT) {
3309 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3310 if (verbose & ~VERBOSE_INHERIT_RR)
3311 llapi_printf(LLAPI_MSG_NORMAL, "lmv_max_inherit_rr: ");
3312 if (lum->lum_max_inherit_rr == LMV_INHERIT_RR_UNLIMITED)
3313 llapi_printf(LLAPI_MSG_NORMAL, "-1");
3314 else if (lum->lum_max_inherit_rr == LMV_INHERIT_RR_NONE)
3315 llapi_printf(LLAPI_MSG_NORMAL, "0");
3317 llapi_printf(LLAPI_MSG_NORMAL, "%hhu",
3318 lum->lum_max_inherit_rr);
3319 if (verbose & VERBOSE_INHERIT_RR && !yaml)
3327 if (verbose & VERBOSE_OBJID && lum->lum_magic != LMV_USER_MAGIC) {
3328 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3329 if (lum->lum_stripe_count > 0)
3330 llapi_printf(LLAPI_MSG_NORMAL,
3331 "mdtidx\t\t FID[seq:oid:ver]\n");
3332 for (i = 0; i < lum->lum_stripe_count; i++) {
3333 int idx = objects[i].lum_mds;
3334 struct lu_fid *fid = &objects[i].lum_fid;
3336 if ((obdindex == OBD_NOT_FOUND) || (obdindex == idx))
3337 llapi_printf(LLAPI_MSG_NORMAL,
3338 "%6u\t\t "DFID"\t\t%s\n",
3340 obdindex == idx ? " *" : "");
3344 if ((verbose & VERBOSE_POOL) && pool_name != NULL &&
3345 pool_name[0] != '\0') {
3346 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3347 if (verbose & ~VERBOSE_POOL)
3348 llapi_printf(LLAPI_MSG_NORMAL, "%slmv_pool: ",
3350 llapi_printf(LLAPI_MSG_NORMAL, "%s%c ", pool_name, ' ');
3354 if (!(verbose & VERBOSE_OBJID) || lum->lum_magic == LMV_USER_MAGIC)
3355 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3358 static void lov_dump_comp_v1_header(struct find_param *param, char *path,
3359 enum lov_dump_flags flags)
3361 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3362 int depth = param->fp_max_depth;
3363 enum llapi_layout_verbose verbose = param->fp_verbose;
3364 bool yaml = flags & LDF_YAML;
3366 if (depth && path && ((verbose != VERBOSE_OBJID) ||
3367 !(flags & LDF_IS_DIR)) && !yaml)
3368 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
3370 if (verbose & VERBOSE_DETAIL) {
3371 llapi_printf(LLAPI_MSG_NORMAL, "composite_header:\n");
3372 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_magic: 0x%08X\n",
3373 " ", comp_v1->lcm_magic);
3374 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_size: %u\n",
3375 " ", comp_v1->lcm_size);
3376 if (flags & LDF_IS_DIR)
3377 llapi_printf(LLAPI_MSG_NORMAL,
3378 "%2slcm_flags: %s\n", " ",
3379 comp_v1->lcm_mirror_count > 0 ?
3382 llapi_printf(LLAPI_MSG_NORMAL,
3383 "%2slcm_flags: %s\n", " ",
3384 llapi_layout_flags_string(comp_v1->lcm_flags));
3387 if (verbose & VERBOSE_GENERATION) {
3388 if (verbose & ~VERBOSE_GENERATION)
3389 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_layout_gen: ",
3391 llapi_printf(LLAPI_MSG_NORMAL, "%u\n", comp_v1->lcm_layout_gen);
3394 if (verbose & VERBOSE_MIRROR_COUNT) {
3395 if (verbose & ~VERBOSE_MIRROR_COUNT)
3396 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_mirror_count: ",
3398 llapi_printf(LLAPI_MSG_NORMAL, "%u\n",
3399 comp_v1->lcm_magic == LOV_USER_MAGIC_COMP_V1 ?
3400 comp_v1->lcm_mirror_count + 1 : 1);
3403 if (verbose & VERBOSE_COMP_COUNT) {
3404 if (verbose & ~VERBOSE_COMP_COUNT)
3405 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_entry_count: ",
3407 llapi_printf(LLAPI_MSG_NORMAL, "%u\n",
3408 comp_v1->lcm_magic == LOV_USER_MAGIC_COMP_V1 ?
3409 comp_v1->lcm_entry_count : 0);
3412 if (verbose & VERBOSE_DETAIL && !yaml)
3413 llapi_printf(LLAPI_MSG_NORMAL, "components:\n");
3416 static void lcme_flags2str(__u32 comp_flags)
3422 llapi_printf(LLAPI_MSG_NORMAL, "0");
3425 for (i = 0; i < ARRAY_SIZE(comp_flags_table); i++) {
3426 if (comp_flags & comp_flags_table[i].cfn_flag) {
3428 llapi_printf(LLAPI_MSG_NORMAL, ",");
3429 llapi_printf(LLAPI_MSG_NORMAL, "%s",
3430 comp_flags_table[i].cfn_name);
3431 comp_flags &= ~comp_flags_table[i].cfn_flag;
3437 llapi_printf(LLAPI_MSG_NORMAL, ",");
3438 llapi_printf(LLAPI_MSG_NORMAL, "%#x", comp_flags);
3442 static void lov_dump_comp_v1_entry(struct find_param *param,
3443 enum lov_dump_flags flags, int index)
3445 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3446 struct lov_comp_md_entry_v1 *entry;
3447 char *separator = "";
3448 enum llapi_layout_verbose verbose = param->fp_verbose;
3449 bool yaml = flags & LDF_YAML;
3451 entry = &comp_v1->lcm_entries[index];
3454 llapi_printf(LLAPI_MSG_NORMAL, "%2scomponent%d:\n", " ", index);
3456 if (verbose & VERBOSE_COMP_ID) {
3457 if (verbose & VERBOSE_DETAIL && !yaml)
3458 llapi_printf(LLAPI_MSG_NORMAL,
3459 "%slcme_id: ", " - ");
3460 else if (verbose & ~VERBOSE_COMP_ID)
3461 llapi_printf(LLAPI_MSG_NORMAL,
3462 "%4slcme_id: ", " ");
3463 if (entry->lcme_id != LCME_ID_INVAL)
3464 llapi_printf(LLAPI_MSG_NORMAL, "%u", entry->lcme_id);
3466 llapi_printf(LLAPI_MSG_NORMAL, "N/A");
3470 if (verbose & VERBOSE_MIRROR_ID) {
3471 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3472 if (verbose & ~VERBOSE_MIRROR_ID)
3473 llapi_printf(LLAPI_MSG_NORMAL,
3474 "%4slcme_mirror_id: ", " ");
3475 if (entry->lcme_id != LCME_ID_INVAL)
3476 llapi_printf(LLAPI_MSG_NORMAL, "%u",
3477 mirror_id_of(entry->lcme_id));
3479 llapi_printf(LLAPI_MSG_NORMAL, "N/A");
3483 if (verbose & VERBOSE_COMP_FLAGS) {
3484 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3485 if (verbose & ~VERBOSE_COMP_FLAGS)
3486 llapi_printf(LLAPI_MSG_NORMAL,
3487 "%4slcme_flags: ", " ");
3488 lcme_flags2str(entry->lcme_flags);
3491 /* print snapshot timestamp if its a nosync comp */
3492 if ((verbose & VERBOSE_COMP_FLAGS) &&
3493 (entry->lcme_flags & LCME_FL_NOSYNC)) {
3494 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3495 if (verbose & ~VERBOSE_COMP_FLAGS)
3496 llapi_printf(LLAPI_MSG_NORMAL,
3497 "%4slcme_timestamp: ", " ");
3499 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3500 (unsigned long long)entry->lcme_timestamp);
3502 time_t stamp = entry->lcme_timestamp;
3503 char *date_str = asctime(localtime(&stamp));
3505 date_str[strlen(date_str) - 1] = '\0';
3506 llapi_printf(LLAPI_MSG_NORMAL, "'%s'", date_str);
3512 if (verbose & VERBOSE_COMP_START) {
3513 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3514 if (verbose & ~VERBOSE_COMP_START)
3515 llapi_printf(LLAPI_MSG_NORMAL,
3516 "%4slcme_extent.e_start: ", " ");
3517 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3518 (unsigned long long)entry->lcme_extent.e_start);
3522 if (verbose & VERBOSE_COMP_END) {
3523 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3524 if (verbose & ~VERBOSE_COMP_END)
3525 llapi_printf(LLAPI_MSG_NORMAL,
3526 "%4slcme_extent.e_end: ", " ");
3527 if (entry->lcme_extent.e_end == LUSTRE_EOF)
3528 llapi_printf(LLAPI_MSG_NORMAL, "%s", "EOF");
3530 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3531 (unsigned long long)entry->lcme_extent.e_end);
3536 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3537 llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " ");
3538 } else if (verbose & VERBOSE_DETAIL) {
3539 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3540 llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_offset: %u\n",
3541 " ", entry->lcme_offset);
3542 llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_size: %u\n",
3543 " ", entry->lcme_size);
3544 llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " ");
3546 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3551 * Check if the value matches 1 of the given criteria (e.g. --atime +/-N).
3552 * @mds indicates if this is MDS timestamps and there are attributes on OSTs.
3554 * The result is -1 if it does not match, 0 if not yet clear, 1 if matches.
3555 * The table below gives the answers for the specified parameters (value and
3556 * sign), 1st column is the answer for the MDS value, the 2nd is for the OST:
3557 * --------------------------------------
3558 * 1 | file > limit; sign > 0 | -1 / -1 |
3559 * 2 | file = limit; sign > 0 | -1 / -1 |
3560 * 3 | file < limit; sign > 0 | ? / 1 |
3561 * 4 | file > limit; sign = 0 | -1 / -1 |
3562 * 5 | file = limit; sign = 0 | ? / 1 | <- (see the Note below)
3563 * 6 | file < limit; sign = 0 | ? / -1 |
3564 * 7 | file > limit; sign < 0 | 1 / 1 |
3565 * 8 | file = limit; sign < 0 | ? / -1 |
3566 * 9 | file < limit; sign < 0 | ? / -1 |
3567 * --------------------------------------
3568 * Note: 5th actually means that the value is within the interval
3569 * (limit - margin, limit].
3571 static int find_value_cmp(unsigned long long file, unsigned long long limit,
3572 int sign, int negopt, unsigned long long margin,
3578 /* Drop the fraction of margin (of days or size). */
3579 if (file + margin <= limit)
3581 } else if (sign == 0) {
3582 if (file <= limit && file + margin > limit)
3584 else if (file + margin <= limit)
3586 } else if (sign < 0) {
3593 return negopt ? ~ret + 1 : ret;
3596 static inline struct lov_user_md *
3597 lov_comp_entry(struct lov_comp_md_v1 *comp_v1, int ent_idx)
3599 return (struct lov_user_md *)((char *)comp_v1 +
3600 comp_v1->lcm_entries[ent_idx].lcme_offset);
3603 static inline struct lov_user_ost_data_v1 *
3604 lov_v1v3_objects(struct lov_user_md *v1)
3606 if (v1->lmm_magic == LOV_USER_MAGIC_V3)
3607 return ((struct lov_user_md_v3 *)v1)->lmm_objects;
3609 return v1->lmm_objects;
3613 lov_v1v3_pool_name(struct lov_user_md *v1, char *pool_name)
3615 if (v1->lmm_magic == LOV_USER_MAGIC_V3)
3616 snprintf(pool_name, LOV_MAXPOOLNAME, "%s",
3617 ((struct lov_user_md_v3 *)v1)->lmm_pool_name);
3619 pool_name[0] = '\0';
3623 print_last_init_comp(struct find_param *param)
3625 /* print all component info */
3626 if ((param->fp_verbose & VERBOSE_DEFAULT) == VERBOSE_DEFAULT)
3629 /* print specific component info */
3630 if (param->fp_check_comp_id || param->fp_check_comp_flags ||
3631 param->fp_check_comp_start || param->fp_check_comp_end ||
3632 param->fp_check_mirror_id || param->fp_check_mirror_index)
3638 static int find_comp_end_cmp(unsigned long long end, struct find_param *param)
3642 if (param->fp_comp_end == LUSTRE_EOF) {
3643 if (param->fp_comp_end_sign == 0) /* equal to EOF */
3644 match = end == LUSTRE_EOF ? 1 : -1;
3645 else if (param->fp_comp_end_sign > 0) /* at most EOF */
3646 match = end == LUSTRE_EOF ? -1 : 1;
3647 else /* at least EOF */
3649 if (param->fp_exclude_comp_end)
3652 unsigned long long margin;
3654 margin = end == LUSTRE_EOF ? 0 : param->fp_comp_end_units;
3655 match = find_value_cmp(end, param->fp_comp_end,
3656 param->fp_comp_end_sign,
3657 param->fp_exclude_comp_end, margin, 0);
3664 * An example of "getstripe -v" for a two components PFL file:
3667 * lcm_magic: 0x0BD60BD0
3671 * lcm_entry_count: 2
3675 * lcme_extent.e_start: 0
3676 * lcme_extent.e_end: 1048576
3680 * lmm_magic: 0x0BD10BD0
3681 * lmm_seq: 0x200000401
3682 * lmm_object_id: 0x1
3683 * lmm_fid: [0x200000401:0x1:0x0]
3684 * lmm_stripe_count: 1
3685 * lmm_stripe_size: 1048576
3686 * lmm_pattern: raid0
3688 * lmm_stripe_offset: 0
3690 * - 0: { l_ost_idx: 0, l_fid: [0x100000000:0x2:0x0] }
3694 * lcme_extent.e_start: 1048576
3695 * lcme_extent.e_end: EOF
3699 * lmm_magic: 0x0BD10BD0
3700 * lmm_seq: 0x200000401
3701 * lmm_object_id: 0x1
3702 * lmm_fid: [0x200000401:0x1:0x0]
3703 * lmm_stripe_count: 2
3704 * lmm_stripe_size: 1048576
3705 * lmm_pattern: raid0
3707 * lmm_stripe_offset: 1
3709 * - 0: { l_ost_idx: 1, l_fid: [0x100010000:0x2:0x0] }
3710 * - 1: { l_ost_idx: 0, l_fid: [0x100000000:0x3:0x0] }
3712 static void lov_dump_comp_v1(struct find_param *param, char *path,
3713 enum lov_dump_flags flags)
3715 struct lov_comp_md_entry_v1 *entry;
3716 struct lov_user_ost_data_v1 *objects;
3717 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3718 struct lov_user_md_v1 *v1;
3719 char pool_name[LOV_MAXPOOLNAME + 1];
3720 int obdindex = param->fp_obd_index;
3721 int i, j, match, ext;
3722 bool obdstripe = false;
3723 __u16 mirror_index = 0;
3724 __u16 mirror_id = 0;
3726 if (obdindex != OBD_NOT_FOUND) {
3727 for (i = 0; !(flags & LDF_IS_DIR) && !obdstripe &&
3728 i < comp_v1->lcm_entry_count; i++) {
3729 if (!(comp_v1->lcm_entries[i].lcme_flags &
3733 v1 = lov_comp_entry(comp_v1, i);
3734 objects = lov_v1v3_objects(v1);
3736 for (j = 0; j < v1->lmm_stripe_count; j++) {
3737 if (obdindex == objects[j].l_ost_idx) {
3750 lov_dump_comp_v1_header(param, path, flags);
3752 flags |= LDF_INDENT;
3754 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
3755 entry = &comp_v1->lcm_entries[i];
3757 if (param->fp_check_comp_flags) {
3758 if (((param->fp_comp_flags & entry->lcme_flags) !=
3759 param->fp_comp_flags) ||
3760 (param->fp_comp_neg_flags & entry->lcme_flags))
3764 if (param->fp_check_comp_id &&
3765 param->fp_comp_id != entry->lcme_id)
3768 if (param->fp_check_comp_start) {
3769 match = find_value_cmp(entry->lcme_extent.e_start,
3770 param->fp_comp_start,
3771 param->fp_comp_start_sign,
3773 param->fp_comp_start_units, 0);
3778 if (param->fp_check_comp_end) {
3779 match = find_comp_end_cmp(entry->lcme_extent.e_end,
3785 if (param->fp_check_mirror_index) {
3786 if (mirror_id != mirror_id_of(entry->lcme_id)) {
3788 mirror_id = mirror_id_of(entry->lcme_id);
3791 match = find_value_cmp(mirror_index,
3792 param->fp_mirror_index,
3793 param->fp_mirror_index_sign,
3794 param->fp_exclude_mirror_index,
3798 } else if (param->fp_check_mirror_id) {
3799 if (mirror_id != mirror_id_of(entry->lcme_id))
3800 mirror_id = mirror_id_of(entry->lcme_id);
3802 match = find_value_cmp(mirror_id,
3803 param->fp_mirror_id,
3804 param->fp_mirror_id_sign,
3805 param->fp_exclude_mirror_id,
3811 if (print_last_init_comp(param)) {
3813 * if part of stripe info is needed, we'd print only
3814 * the last instantiated component info.
3816 if (entry->lcme_flags & LCME_FL_INIT)
3819 if (param->fp_verbose & VERBOSE_EXT_SIZE) {
3820 if (entry->lcme_flags & LCME_FL_EXTENSION)
3821 /* moved back below */
3829 if (entry->lcme_flags & LCME_FL_INIT) {
3830 if (obdindex != OBD_NOT_FOUND) {
3831 flags |= LDF_SKIP_OBJS;
3832 v1 = lov_comp_entry(comp_v1, i);
3833 objects = lov_v1v3_objects(v1);
3835 for (j = 0; j < v1->lmm_stripe_count; j++) {
3836 if (obdindex == objects[j].l_ost_idx) {
3837 flags &= ~LDF_SKIP_OBJS;
3842 flags &= ~LDF_SKIP_OBJS;
3845 flags |= LDF_SKIP_OBJS;
3848 if (obdindex != OBD_NOT_FOUND && (flags & LDF_SKIP_OBJS))
3850 lov_dump_comp_v1_entry(param, flags, i);
3852 v1 = lov_comp_entry(comp_v1, i);
3853 objects = lov_v1v3_objects(v1);
3854 lov_v1v3_pool_name(v1, pool_name);
3856 ext = entry->lcme_flags & LCME_FL_EXTENSION ? LDF_EXTENSION : 0;
3857 lov_dump_user_lmm_v1v3(v1, pool_name, objects, path, obdindex,
3858 param->fp_max_depth, param->fp_verbose,
3861 if (print_last_init_comp(param)) {
3863 * directory layout contains only layout template, print the
3867 i = comp_v1->lcm_entry_count - 1;
3870 flags &= ~LDF_SKIP_OBJS;
3872 lov_dump_comp_v1_entry(param, flags, i);
3874 v1 = lov_comp_entry(comp_v1, i);
3875 objects = lov_v1v3_objects(v1);
3876 lov_v1v3_pool_name(v1, pool_name);
3878 entry = &comp_v1->lcm_entries[i];
3879 ext = entry->lcme_flags & LCME_FL_EXTENSION ? LDF_EXTENSION : 0;
3880 lov_dump_user_lmm_v1v3(v1, pool_name, objects, path, obdindex,
3881 param->fp_max_depth, param->fp_verbose,
3886 #define VERBOSE_COMP_OPTS (VERBOSE_COMP_COUNT | VERBOSE_COMP_ID | \
3887 VERBOSE_COMP_START | VERBOSE_COMP_END | \
3890 static inline bool has_any_comp_options(struct find_param *param)
3892 enum llapi_layout_verbose verbose = param->fp_verbose;
3894 if (param->fp_check_comp_id || param->fp_check_comp_count ||
3895 param->fp_check_comp_start || param->fp_check_comp_end ||
3896 param->fp_check_comp_flags)
3899 /* show full layout information, not component specific */
3900 if ((verbose & ~VERBOSE_DETAIL) == VERBOSE_DEFAULT)
3903 return verbose & VERBOSE_COMP_OPTS;
3906 struct lov_user_mds_data *lov_forge_comp_v1(struct lov_user_mds_data *orig,
3909 struct lov_user_md *lum = &orig->lmd_lmm;
3910 struct lov_user_mds_data *new;
3911 struct lov_comp_md_v1 *comp_v1;
3912 struct lov_comp_md_entry_v1 *ent;
3913 int lum_off = sizeof(*comp_v1) + sizeof(*ent);
3914 int lum_size = lov_user_md_size(is_dir ? 0 : lum->lmm_stripe_count,
3917 new = malloc(offsetof(typeof(*new), lmd_lmm) + lum_off + lum_size);
3919 llapi_printf(LLAPI_MSG_NORMAL, "out of memory\n");
3923 memcpy(new, orig, sizeof(new->lmd_stx) + sizeof(new->lmd_flags)
3924 + sizeof(new->lmd_lmmsize));
3926 comp_v1 = (struct lov_comp_md_v1 *)&new->lmd_lmm;
3927 comp_v1->lcm_magic = lum->lmm_magic;
3928 comp_v1->lcm_size = lum_off + lum_size;
3929 comp_v1->lcm_layout_gen = is_dir ? 0 : lum->lmm_layout_gen;
3930 comp_v1->lcm_flags = 0;
3931 comp_v1->lcm_entry_count = 1;
3933 ent = &comp_v1->lcm_entries[0];
3935 ent->lcme_flags = is_dir ? 0 : LCME_FL_INIT;
3936 ent->lcme_extent.e_start = 0;
3937 ent->lcme_extent.e_end = LUSTRE_EOF;
3938 ent->lcme_offset = lum_off;
3939 ent->lcme_size = lum_size;
3941 memcpy((char *)comp_v1 + lum_off, lum, lum_size);
3946 static void lov_dump_plain_user_lmm(struct find_param *param, char *path,
3947 enum lov_dump_flags flags)
3949 __u32 magic = *(__u32 *)¶m->fp_lmd->lmd_lmm;
3951 if (has_any_comp_options(param)) {
3952 struct lov_user_mds_data *new_lmd, *orig_lmd;
3954 orig_lmd = param->fp_lmd;
3955 new_lmd = lov_forge_comp_v1(orig_lmd, flags & LDF_IS_DIR);
3956 if (new_lmd != NULL) {
3957 param->fp_lmd = new_lmd;
3958 lov_dump_comp_v1(param, path, flags);
3959 param->fp_lmd = orig_lmd;
3965 if (magic == LOV_USER_MAGIC_V1) {
3966 lov_dump_user_lmm_v1v3(¶m->fp_lmd->lmd_lmm, NULL,
3967 param->fp_lmd->lmd_lmm.lmm_objects,
3968 path, param->fp_obd_index,
3969 param->fp_max_depth, param->fp_verbose,
3972 char pool_name[LOV_MAXPOOLNAME + 1];
3973 struct lov_user_ost_data_v1 *objects;
3974 struct lov_user_md_v3 *lmmv3 = (void *)¶m->fp_lmd->lmd_lmm;
3976 snprintf(pool_name, sizeof(pool_name), "%s",
3977 lmmv3->lmm_pool_name);
3978 objects = lmmv3->lmm_objects;
3979 lov_dump_user_lmm_v1v3(¶m->fp_lmd->lmd_lmm, pool_name,
3980 objects, path, param->fp_obd_index,
3981 param->fp_max_depth, param->fp_verbose,
3986 static uint32_t check_foreign_type(uint32_t foreign_type)
3990 for (i = 0; i < LU_FOREIGN_TYPE_UNKNOWN; i++) {
3991 if (lu_foreign_types[i].lft_name == NULL)
3993 if (foreign_type == lu_foreign_types[i].lft_type)
3997 return LU_FOREIGN_TYPE_UNKNOWN;
4000 static void lov_dump_foreign_lmm(struct find_param *param, char *path,
4001 enum lov_dump_flags flags)
4003 struct lov_foreign_md *lfm = (void *)¶m->fp_lmd->lmd_lmm;
4004 bool yaml = flags & LDF_YAML;
4006 if (!yaml && param->fp_depth && path)
4007 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
4009 if (param->fp_verbose & VERBOSE_DETAIL) {
4010 uint32_t type = check_foreign_type(lfm->lfm_type);
4012 llapi_printf(LLAPI_MSG_NORMAL, "lfm_magic: 0x%08X\n",
4014 llapi_printf(LLAPI_MSG_NORMAL, "lfm_length: %u\n",
4016 llapi_printf(LLAPI_MSG_NORMAL, "lfm_type: 0x%08X",
4018 if (type < LU_FOREIGN_TYPE_UNKNOWN)
4019 llapi_printf(LLAPI_MSG_NORMAL, " (%s)\n",
4020 lu_foreign_types[type].lft_name);
4022 llapi_printf(LLAPI_MSG_NORMAL, " (unknown)\n");
4024 llapi_printf(LLAPI_MSG_NORMAL, "lfm_flags: 0x%08X\n",
4027 llapi_printf(LLAPI_MSG_NORMAL, "lfm_value: '%.*s'\n",
4028 lfm->lfm_length, lfm->lfm_value);
4029 llapi_printf(LLAPI_MSG_NORMAL, "\n");
4032 static void lmv_dump_foreign_lmm(struct find_param *param, char *path,
4033 enum lov_dump_flags flags)
4035 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)param->fp_lmv_md;
4036 bool yaml = flags & LDF_YAML;
4038 if (!yaml && param->fp_depth && path)
4039 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
4041 if (param->fp_verbose & VERBOSE_DETAIL) {
4042 uint32_t type = check_foreign_type(lfm->lfm_type);
4044 llapi_printf(LLAPI_MSG_NORMAL, "lfm_magic: 0x%08X\n",
4046 llapi_printf(LLAPI_MSG_NORMAL, "lfm_length: %u\n",
4048 llapi_printf(LLAPI_MSG_NORMAL, "lfm_type: 0x%08X",
4050 if (type < LU_FOREIGN_TYPE_UNKNOWN)
4051 llapi_printf(LLAPI_MSG_NORMAL, " (%s)\n",
4052 lu_foreign_types[type].lft_name);
4054 llapi_printf(LLAPI_MSG_NORMAL, " (unknown)\n");
4056 llapi_printf(LLAPI_MSG_NORMAL, "lfm_flags: 0x%08X\n",
4059 llapi_printf(LLAPI_MSG_NORMAL, "lfm_value: '%.*s'\n",
4060 lfm->lfm_length, lfm->lfm_value);
4061 llapi_printf(LLAPI_MSG_NORMAL, "\n");
4064 static void llapi_lov_dump_user_lmm(struct find_param *param, char *path,
4065 enum lov_dump_flags flags)
4069 if (param->fp_get_lmv || param->fp_get_default_lmv)
4070 magic = (__u32)param->fp_lmv_md->lum_magic;
4072 magic = *(__u32 *)¶m->fp_lmd->lmd_lmm; /* lum->lmm_magic */
4075 flags |= LDF_IS_RAW;
4080 case LOV_USER_MAGIC_V1:
4081 case LOV_USER_MAGIC_V3:
4082 case LOV_USER_MAGIC_SPECIFIC:
4083 lov_dump_plain_user_lmm(param, path, flags);
4085 case LOV_USER_MAGIC_FOREIGN:
4086 lov_dump_foreign_lmm(param, path, flags);
4089 case LMV_USER_MAGIC: {
4090 char pool_name[LOV_MAXPOOLNAME + 1];
4091 struct lmv_user_md *lum;
4093 lum = (struct lmv_user_md *)param->fp_lmv_md;
4094 snprintf(pool_name, sizeof(pool_name), "%s",
4095 lum->lum_pool_name);
4096 lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index,
4097 param->fp_max_depth, param->fp_verbose,
4101 case LOV_USER_MAGIC_COMP_V1:
4102 lov_dump_comp_v1(param, path, flags);
4104 case LMV_MAGIC_FOREIGN:
4105 lmv_dump_foreign_lmm(param, path, flags);
4108 llapi_printf(LLAPI_MSG_NORMAL,
4109 "unknown lmm_magic: %#x (expecting one of %#x %#x %#x %#x)\n",
4110 *(__u32 *)¶m->fp_lmd->lmd_lmm,
4111 LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3,
4112 LMV_USER_MAGIC, LMV_MAGIC_V1);
4117 static int llapi_file_get_stripe1(const char *path, struct lov_user_md *lum)
4123 fname = strrchr(path, '/');
4125 /* It should be a file (or other non-directory) */
4126 if (fname == NULL) {
4127 dname = (char *)malloc(2);
4131 fname = (char *)path;
4133 dname = (char *)malloc(fname - path + 1);
4136 strncpy(dname, path, fname - path);
4137 dname[fname - path] = '\0';
4141 fd = open(dname, O_RDONLY | O_NONBLOCK);
4147 strcpy((char *)lum, fname);
4148 if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
4151 if (close(fd) == -1 && rc == 0)
4159 int llapi_file_get_stripe(const char *path, struct lov_user_md *lum)
4161 char *canon_path = NULL;
4164 rc = llapi_file_get_stripe1(path, lum);
4165 if (!(rc == -ENOTTY || rc == -ENODATA))
4168 /* Handle failure due to symlinks by dereferencing path manually. */
4169 canon_path = canonicalize_file_name(path);
4170 if (canon_path == NULL)
4171 goto out; /* Keep original rc. */
4173 rc2 = llapi_file_get_stripe1(canon_path, lum);
4175 goto out; /* Keep original rc. */
4184 int llapi_file_lookup(int dirfd, const char *name)
4186 struct obd_ioctl_data data = { 0 };
4191 if (dirfd < 0 || name == NULL)
4194 data.ioc_version = OBD_IOCTL_VERSION;
4195 data.ioc_len = sizeof(data);
4196 data.ioc_inlbuf1 = (char *)name;
4197 data.ioc_inllen1 = strlen(name) + 1;
4199 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
4201 llapi_error(LLAPI_MSG_ERROR, rc,
4202 "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
4207 rc = ioctl(dirfd, IOC_MDC_LOOKUP, buf);
4214 * Check if the file time matches all the given criteria (e.g. --atime +/-N).
4215 * Return -1 or 1 if file timestamp does not or does match the given criteria
4216 * correspondingly. Return 0 if the MDS time is being checked and there are
4217 * attributes on OSTs and it is not yet clear if the timespamp matches.
4219 * If 0 is returned, we need to do another RPC to the OSTs to obtain the
4220 * updated timestamps.
4222 static int find_time_check(struct find_param *param, int mds)
4224 struct lov_user_mds_data *lmd = param->fp_lmd;
4228 /* Check if file is accepted. */
4229 if (param->fp_atime) {
4230 rc2 = find_value_cmp(lmd->lmd_stx.stx_atime.tv_sec,
4231 param->fp_atime, param->fp_asign,
4232 param->fp_exclude_atime,
4233 param->fp_time_margin, mds);
4239 if (param->fp_mtime) {
4240 rc2 = find_value_cmp(lmd->lmd_stx.stx_mtime.tv_sec,
4241 param->fp_mtime, param->fp_msign,
4242 param->fp_exclude_mtime,
4243 param->fp_time_margin, mds);
4248 * If the previous check matches, but this one is not yet clear,
4249 * we should return 0 to do an RPC on OSTs.
4255 if (param->fp_ctime) {
4256 rc2 = find_value_cmp(lmd->lmd_stx.stx_ctime.tv_sec,
4257 param->fp_ctime, param->fp_csign,
4258 param->fp_exclude_ctime,
4259 param->fp_time_margin, mds);
4264 * If the previous check matches, but this one is not yet clear,
4265 * we should return 0 to do an RPC on OSTs.
4274 static int find_newerxy_check(struct find_param *param, int mds, bool from_mdt)
4276 struct lov_user_mds_data *lmd = param->fp_lmd;
4281 for (i = 0; i < 2; i++) {
4282 /* Check if file is accepted. */
4283 if (param->fp_newery[NEWERXY_ATIME][i]) {
4284 rc2 = find_value_cmp(lmd->lmd_stx.stx_atime.tv_sec,
4285 param->fp_newery[NEWERXY_ATIME][i],
4292 if (param->fp_newery[NEWERXY_MTIME][i]) {
4293 rc2 = find_value_cmp(lmd->lmd_stx.stx_mtime.tv_sec,
4294 param->fp_newery[NEWERXY_MTIME][i],
4300 * If the previous check matches, but this one is not
4301 * yet clear, we should return 0 to do an RPC on OSTs.
4307 if (param->fp_newery[NEWERXY_CTIME][i]) {
4308 rc2 = find_value_cmp(lmd->lmd_stx.stx_ctime.tv_sec,
4309 param->fp_newery[NEWERXY_CTIME][i],
4315 * If the previous check matches, but this one is not
4316 * yet clear, we should return 0 to do an RPC on OSTs.
4323 * File birth time (btime) can get from MDT directly.
4324 * if @from_mdt is true, it means the input file attributs are
4325 * obtained directly from MDT.
4326 * Thus, if @from_mdt is false, we should skip the following
4332 if (param->fp_newery[NEWERXY_BTIME][i]) {
4333 if (!(lmd->lmd_stx.stx_mask & STATX_BTIME))
4336 rc2 = find_value_cmp(lmd->lmd_stx.stx_btime.tv_sec,
4337 param->fp_newery[NEWERXY_BTIME][i],
4348 * Check whether the stripes matches the indexes user provided
4352 static int check_obd_match(struct find_param *param)
4354 struct lov_user_ost_data_v1 *objects;
4355 struct lov_comp_md_v1 *comp_v1 = NULL;
4356 struct lov_user_mds_data *lmd = param->fp_lmd;
4357 struct lov_user_md_v1 *v1 = &lmd->lmd_lmm;
4358 int i, j, k, count = 1;
4360 if (param->fp_obd_uuid && param->fp_obd_index == OBD_NOT_FOUND)
4363 if (!S_ISREG(lmd->lmd_stx.stx_mode))
4366 /* exclude foreign */
4367 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4368 return param->fp_exclude_obd;
4371 * Only those files should be accepted, which have a
4372 * stripe on the specified OST.
4374 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4375 comp_v1 = (struct lov_comp_md_v1 *)v1;
4376 count = comp_v1->lcm_entry_count;
4379 for (i = 0; i < count; i++) {
4381 v1 = lov_comp_entry(comp_v1, i);
4383 objects = lov_v1v3_objects(v1);
4385 for (j = 0; j < v1->lmm_stripe_count; j++) {
4386 if (comp_v1 && !(comp_v1->lcm_entries[i].lcme_flags &
4389 for (k = 0; k < param->fp_num_obds; k++) {
4390 if (param->fp_obd_indexes[k] ==
4391 objects[j].l_ost_idx)
4392 return !param->fp_exclude_obd;
4397 return param->fp_exclude_obd;
4400 static int check_mdt_match(struct find_param *param)
4404 if (param->fp_mdt_uuid && param->fp_mdt_index == OBD_NOT_FOUND)
4407 /* FIXME: For striped dir, we should get stripe information and check */
4408 for (i = 0; i < param->fp_num_mdts; i++) {
4409 if (param->fp_mdt_indexes[i] == param->fp_file_mdt_index)
4410 return !param->fp_exclude_mdt;
4413 if (param->fp_exclude_mdt)
4420 * Check whether the obd is active or not, if it is
4421 * not active, just print the object affected by this
4424 static void print_failed_tgt(struct find_param *param, char *path, int type)
4426 struct obd_statfs stat_buf;
4427 struct obd_uuid uuid_buf;
4428 int tgt_nr, i, *indexes;
4431 if (type != LL_STATFS_LOV && type != LL_STATFS_LMV) {
4432 llapi_error(LLAPI_MSG_NORMAL, ret, "%s: wrong statfs type(%d)",
4437 tgt_nr = (type == LL_STATFS_LOV) ? param->fp_obd_index :
4438 param->fp_mdt_index;
4439 indexes = (type == LL_STATFS_LOV) ? param->fp_obd_indexes :
4440 param->fp_mdt_indexes;
4442 for (i = 0; i < tgt_nr; i++) {
4443 memset(&stat_buf, 0, sizeof(struct obd_statfs));
4444 memset(&uuid_buf, 0, sizeof(struct obd_uuid));
4446 ret = llapi_obd_statfs(path, type, indexes[i], &stat_buf,
4449 llapi_error(LLAPI_MSG_NORMAL, ret,
4450 "%s: obd_uuid: %s failed",
4451 __func__, param->fp_obd_uuid->uuid);
4455 static int find_check_stripe_size(struct find_param *param)
4457 struct lov_comp_md_v1 *comp_v1 = NULL;
4458 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4459 __u32 stripe_size = 0;
4460 int ret, i, count = 1;
4462 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4463 return param->fp_exclude_stripe_size ? 1 : -1;
4465 ret = param->fp_exclude_stripe_size ? 1 : -1;
4466 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4467 comp_v1 = (struct lov_comp_md_v1 *)v1;
4468 count = comp_v1->lcm_entry_count;
4471 for (i = 0; i < count; i++) {
4472 struct lov_comp_md_entry_v1 *ent;
4475 v1 = lov_comp_entry(comp_v1, i);
4477 ent = &comp_v1->lcm_entries[i];
4478 if (ent->lcme_flags & LCME_FL_EXTENSION)
4480 if (!(ent->lcme_flags & LCME_FL_INIT))
4483 stripe_size = v1->lmm_stripe_size;
4486 ret = find_value_cmp(stripe_size, param->fp_stripe_size,
4487 param->fp_stripe_size_sign,
4488 param->fp_exclude_stripe_size,
4489 param->fp_stripe_size_units, 0);
4494 static int find_check_ext_size(struct find_param *param)
4496 struct lov_comp_md_v1 *comp_v1;
4497 struct lov_user_md_v1 *v1;
4500 ret = param->fp_exclude_ext_size ? 1 : -1;
4501 comp_v1 = (struct lov_comp_md_v1 *)¶m->fp_lmd->lmd_lmm;
4502 if (comp_v1->lcm_magic != LOV_USER_MAGIC_COMP_V1)
4505 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
4506 struct lov_comp_md_entry_v1 *ent;
4508 v1 = lov_comp_entry(comp_v1, i);
4510 ent = &comp_v1->lcm_entries[i];
4511 if (!(ent->lcme_flags & LCME_FL_EXTENSION))
4514 ret = find_value_cmp(v1->lmm_stripe_size, param->fp_ext_size,
4515 param->fp_ext_size_sign,
4516 param->fp_exclude_ext_size,
4517 param->fp_ext_size_units, 0);
4518 /* If any ext_size matches */
4526 static __u32 find_get_stripe_count(struct find_param *param)
4528 struct lov_comp_md_v1 *comp_v1 = NULL;
4529 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4531 __u32 stripe_count = 0;
4533 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4536 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4537 comp_v1 = (struct lov_comp_md_v1 *)v1;
4538 count = comp_v1->lcm_entry_count;
4541 for (i = 0; i < count; i++) {
4543 struct lov_comp_md_entry_v1 *ent;
4545 v1 = lov_comp_entry(comp_v1, i);
4547 ent = &comp_v1->lcm_entries[i];
4548 if (!(ent->lcme_flags & LCME_FL_INIT))
4551 if (ent->lcme_flags & LCME_FL_EXTENSION)
4554 stripe_count = v1->lmm_stripe_count;
4557 return stripe_count;
4560 #define LOV_PATTERN_INVALID 0xFFFFFFFF
4562 static int find_check_layout(struct find_param *param)
4564 struct lov_comp_md_v1 *comp_v1 = NULL;
4565 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4567 bool found = false, valid = false;
4569 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4570 comp_v1 = (struct lov_comp_md_v1 *)v1;
4571 count = comp_v1->lcm_entry_count;
4574 for (i = 0; i < count; i++) {
4576 v1 = lov_comp_entry(comp_v1, i);
4578 /* foreign file have a special magic but no pattern field */
4579 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4582 if (v1->lmm_pattern == LOV_PATTERN_INVALID)
4586 if (v1->lmm_pattern & param->fp_layout) {
4595 if ((found && !param->fp_exclude_layout) ||
4596 (!found && param->fp_exclude_layout))
4603 * if no type specified, check/exclude all foreign
4604 * if type specified, check all foreign&type and exclude !foreign + foreign&type
4606 static int find_check_foreign(struct find_param *param)
4608 if (S_ISREG(param->fp_lmd->lmd_stx.stx_mode)) {
4609 struct lov_foreign_md *lfm;
4611 lfm = (void *)¶m->fp_lmd->lmd_lmm;
4612 if (lfm->lfm_magic != LOV_USER_MAGIC_FOREIGN) {
4613 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN)
4614 return param->fp_exclude_foreign ? 1 : -1;
4618 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN ||
4619 lfm->lfm_type == param->fp_foreign_type)
4620 return param->fp_exclude_foreign ? -1 : 1;
4621 return param->fp_exclude_foreign ? 1 : -1;
4624 if (S_ISDIR(param->fp_lmd->lmd_stx.stx_mode)) {
4625 struct lmv_foreign_md *lfm;
4627 lfm = (void *)param->fp_lmv_md;
4628 if (lfm->lfm_magic != LMV_MAGIC_FOREIGN) {
4629 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN)
4630 return param->fp_exclude_foreign ? 1 : -1;
4634 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN ||
4635 lfm->lfm_type == param->fp_foreign_type)
4636 return param->fp_exclude_foreign ? -1 : 1;
4637 return param->fp_exclude_foreign ? 1 : -1;
4642 static int find_check_pool(struct find_param *param)
4644 struct lov_comp_md_v1 *comp_v1 = NULL;
4645 struct lov_user_md_v3 *v3 = (void *)¶m->fp_lmd->lmd_lmm;
4649 if (v3->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4650 comp_v1 = (struct lov_comp_md_v1 *)v3;
4651 count = comp_v1->lcm_entry_count;
4652 /* empty requested pool is taken as no pool search */
4653 if (count == 0 && param->fp_poolname[0] == '\0') {
4659 for (i = 0; i < count; i++) {
4660 if (comp_v1 != NULL) {
4661 if (!(comp_v1->lcm_entries[i].lcme_flags &
4665 v3 = (void *)lov_comp_entry(comp_v1, i);
4668 if (v3->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4671 if (((v3->lmm_magic == LOV_USER_MAGIC_V1) &&
4672 (param->fp_poolname[0] == '\0')) ||
4673 ((v3->lmm_magic == LOV_USER_MAGIC_V3) &&
4674 (strncmp(v3->lmm_pool_name,
4675 param->fp_poolname, LOV_MAXPOOLNAME) == 0)) ||
4676 ((v3->lmm_magic == LOV_USER_MAGIC_V3) &&
4677 (strcmp(param->fp_poolname, "*") == 0))) {
4684 if ((found && !param->fp_exclude_pool) ||
4685 (!found && param->fp_exclude_pool))
4691 static int find_check_comp_options(struct find_param *param)
4693 struct lov_comp_md_v1 *comp_v1, *forged_v1 = NULL;
4694 struct lov_user_mds_data *lmd = param->fp_lmd;
4695 struct lov_user_md_v1 *v1 = &lmd->lmd_lmm;
4696 struct lov_comp_md_entry_v1 *entry;
4699 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4702 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4703 comp_v1 = (struct lov_comp_md_v1 *)v1;
4705 forged_v1 = malloc(sizeof(*forged_v1) + sizeof(*entry));
4706 if (forged_v1 == NULL)
4708 comp_v1 = forged_v1;
4709 comp_v1->lcm_entry_count = 1;
4710 entry = &comp_v1->lcm_entries[0];
4711 entry->lcme_flags = S_ISDIR(lmd->lmd_stx.stx_mode) ?
4713 entry->lcme_extent.e_start = 0;
4714 entry->lcme_extent.e_end = LUSTRE_EOF;
4717 /* invalid case, don't match for any kind of search. */
4718 if (comp_v1->lcm_entry_count == 0) {
4723 if (param->fp_check_comp_count) {
4724 ret = find_value_cmp(forged_v1 ? 0 : comp_v1->lcm_entry_count,
4725 param->fp_comp_count,
4726 param->fp_comp_count_sign,
4727 param->fp_exclude_comp_count, 1, 0);
4733 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
4734 entry = &comp_v1->lcm_entries[i];
4736 if (param->fp_check_comp_flags) {
4738 if (((param->fp_comp_flags & entry->lcme_flags) !=
4739 param->fp_comp_flags) ||
4740 (param->fp_comp_neg_flags & entry->lcme_flags)) {
4746 if (param->fp_check_comp_start) {
4747 ret = find_value_cmp(entry->lcme_extent.e_start,
4748 param->fp_comp_start,
4749 param->fp_comp_start_sign,
4750 param->fp_exclude_comp_start,
4751 param->fp_comp_start_units, 0);
4756 if (param->fp_check_comp_end) {
4757 ret = find_comp_end_cmp(entry->lcme_extent.e_end,
4763 /* the component matches all criteria */
4772 static int find_check_mirror_options(struct find_param *param)
4774 struct lov_comp_md_v1 *comp_v1;
4775 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4778 if (v1->lmm_magic != LOV_USER_MAGIC_COMP_V1)
4781 comp_v1 = (struct lov_comp_md_v1 *)v1;
4783 if (param->fp_check_mirror_count) {
4784 ret = find_value_cmp(comp_v1->lcm_mirror_count + 1,
4785 param->fp_mirror_count,
4786 param->fp_mirror_count_sign,
4787 param->fp_exclude_mirror_count, 1, 0);
4792 if (param->fp_check_mirror_state) {
4794 __u16 file_state = comp_v1->lcm_flags & LCM_FL_FLR_MASK;
4796 if ((param->fp_mirror_state != 0 &&
4797 file_state != param->fp_mirror_state) ||
4798 file_state == param->fp_mirror_neg_state)
4805 static bool find_check_lmm_info(struct find_param *param)
4807 return param->fp_check_pool || param->fp_check_stripe_count ||
4808 param->fp_check_stripe_size || param->fp_check_layout ||
4809 param->fp_check_comp_count || param->fp_check_comp_end ||
4810 param->fp_check_comp_start || param->fp_check_comp_flags ||
4811 param->fp_check_mirror_count || param->fp_check_foreign ||
4812 param->fp_check_mirror_state || param->fp_check_ext_size ||
4813 param->fp_check_projid;
4817 * Get file/directory project id.
4818 * by the open fd resides on.
4819 * Return 0 and project id on success, or -ve errno.
4821 static int fget_projid(int fd, int *projid)
4826 rc = ioctl(fd, FS_IOC_FSGETXATTR, &fsx);
4830 *projid = fsx.fsx_projid;
4834 static int cb_find_init(char *path, int p, int *dp,
4835 void *data, struct dirent64 *de)
4837 struct find_param *param = (struct find_param *)data;
4838 struct lov_user_mds_data *lmd = param->fp_lmd;
4839 int d = dp == NULL ? -1 : *dp;
4840 int decision = 1; /* 1 is accepted; -1 is rejected. */
4842 int checked_type = 0;
4844 __u32 stripe_count = 0;
4848 if (p == -1 && d == -1)
4851 /* If a regular expression is presented, make the initial decision */
4852 if (param->fp_pattern != NULL) {
4853 char *fname = strrchr(path, '/');
4855 fname = (fname == NULL ? path : fname + 1);
4856 ret = fnmatch(param->fp_pattern, fname, 0);
4857 if ((ret == FNM_NOMATCH && !param->fp_exclude_pattern) ||
4858 (ret == 0 && param->fp_exclude_pattern))
4862 /* See if we can check the file type from the dirent. */
4863 if (param->fp_type != 0 && de != NULL && de->d_type != DT_UNKNOWN) {
4866 if (DTTOIF(de->d_type) == param->fp_type) {
4867 if (param->fp_exclude_type)
4870 if (!param->fp_exclude_type)
4878 * Request MDS for the stat info if some of these parameters need
4881 if (param->fp_obd_uuid || param->fp_mdt_uuid ||
4882 param->fp_check_uid || param->fp_check_gid ||
4883 param->fp_newerxy || param->fp_btime ||
4884 param->fp_atime || param->fp_mtime || param->fp_ctime ||
4885 param->fp_check_size || param->fp_check_blocks ||
4886 find_check_lmm_info(param) ||
4887 param->fp_check_mdt_count || param->fp_hash_type ||
4888 param->fp_check_hash_flag)
4891 if (param->fp_type != 0 && checked_type == 0)
4894 if (decision == 0) {
4895 if (d != -1 && (param->fp_check_mdt_count ||
4896 param->fp_hash_type || param->fp_check_foreign ||
4897 param->fp_check_hash_flag)) {
4898 param->fp_get_lmv = 1;
4899 ret = cb_get_dirstripe(path, &d, param);
4902 * XXX this works to decide for foreign
4905 if (errno == ENODATA &&
4906 param->fp_check_foreign) {
4907 if (param->fp_exclude_foreign)
4915 param->fp_lmd->lmd_lmm.lmm_magic = 0;
4916 ret = get_lmd_info_fd(path, p, d, param->fp_lmd,
4917 param->fp_lum_size, GET_LMD_INFO);
4918 if (ret == 0 && param->fp_lmd->lmd_lmm.lmm_magic == 0 &&
4919 find_check_lmm_info(param)) {
4920 struct lov_user_md *lmm = ¶m->fp_lmd->lmd_lmm;
4923 * We need to "fake" the "use the default" values
4924 * since the lmm struct is zeroed out at this point.
4926 lmm->lmm_magic = LOV_USER_MAGIC_V1;
4927 lmm->lmm_pattern = LOV_PATTERN_DEFAULT;
4929 ostid_set_seq(&lmm->lmm_oi,
4930 FID_SEQ_LOV_DEFAULT);
4931 lmm->lmm_stripe_size = 0;
4932 lmm->lmm_stripe_count = 0;
4933 lmm->lmm_stripe_offset = -1;
4935 if (ret == 0 && param->fp_mdt_uuid != NULL) {
4937 ret = llapi_file_fget_mdtidx(d,
4938 ¶m->fp_file_mdt_index);
4939 } else if (S_ISREG(lmd->lmd_stx.stx_mode)) {
4941 * FIXME: we could get the MDT index from the
4942 * file's FID in lmd->lmd_lmm.lmm_oi without
4943 * opening the file, once we are sure that
4944 * LFSCK2 (2.6) has fixed up pre-2.0 LOV EAs.
4945 * That would still be an ioctl() to map the
4946 * FID to the MDT, but not an open RPC.
4948 fd = open(path, O_RDONLY);
4950 ret = llapi_file_fget_mdtidx(fd,
4951 ¶m->fp_file_mdt_index);
4957 * For a special file, we assume it resides on
4958 * the same MDT as the parent directory.
4960 ret = llapi_file_fget_mdtidx(p,
4961 ¶m->fp_file_mdt_index);
4972 stripe_count = find_get_stripe_count(param);
4976 if (param->fp_type && !checked_type) {
4977 if ((lmd->lmd_stx.stx_mode & S_IFMT) == param->fp_type) {
4978 if (param->fp_exclude_type)
4981 if (!param->fp_exclude_type)
4987 if (param->fp_obd_uuid || param->fp_mdt_uuid) {
4988 if (lustre_fs && param->fp_got_uuids &&
4989 param->fp_dev != makedev(lmd->lmd_stx.stx_dev_major,
4990 lmd->lmd_stx.stx_dev_minor)) {
4991 /* A lustre/lustre mount point is crossed. */
4992 param->fp_got_uuids = 0;
4993 param->fp_obds_printed = 0;
4994 param->fp_mdt_index = OBD_NOT_FOUND;
4995 param->fp_obd_index = OBD_NOT_FOUND;
4998 if (lustre_fs && !param->fp_got_uuids) {
4999 ret = setup_target_indexes((d != -1) ? d : p, path,
5004 param->fp_dev = makedev(lmd->lmd_stx.stx_dev_major,
5005 lmd->lmd_stx.stx_dev_minor);
5006 } else if (!lustre_fs && param->fp_got_uuids) {
5007 /* A lustre/non-lustre mount point is crossed. */
5008 param->fp_got_uuids = 0;
5009 param->fp_mdt_index = OBD_NOT_FOUND;
5010 param->fp_obd_index = OBD_NOT_FOUND;
5014 if (param->fp_check_foreign) {
5015 decision = find_check_foreign(param);
5020 if (param->fp_check_stripe_size) {
5021 decision = find_check_stripe_size(param);
5026 if (param->fp_check_ext_size) {
5027 decision = find_check_ext_size(param);
5032 if (param->fp_check_stripe_count) {
5033 decision = find_value_cmp(stripe_count, param->fp_stripe_count,
5034 param->fp_stripe_count_sign,
5035 param->fp_exclude_stripe_count, 1, 0);
5040 if (param->fp_check_mdt_count) {
5041 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
5046 decision = find_value_cmp(
5047 param->fp_lmv_md->lum_stripe_count,
5048 param->fp_mdt_count,
5049 param->fp_mdt_count_sign,
5050 param->fp_exclude_mdt_count, 1, 0);
5055 if (param->fp_check_layout) {
5056 decision = find_check_layout(param);
5061 if (param->fp_hash_type) {
5063 __u32 type = param->fp_lmv_md->lum_hash_type &
5066 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
5071 found = (1 << type) & param->fp_hash_type;
5072 if ((found && param->fp_exclude_hash_type) ||
5073 (!found && !param->fp_exclude_hash_type)) {
5079 if (param->fp_check_hash_flag) {
5080 __u32 flags = param->fp_lmv_md->lum_hash_type &
5081 ~LMV_HASH_TYPE_MASK;
5083 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
5088 if (!(flags & param->fp_hash_inflags) ||
5089 (flags & param->fp_hash_exflags)) {
5095 /* If an OBD UUID is specified but none matches, skip this file. */
5096 if ((param->fp_obd_uuid && param->fp_obd_index == OBD_NOT_FOUND) ||
5097 (param->fp_mdt_uuid && param->fp_mdt_index == OBD_NOT_FOUND))
5101 * If an OST or MDT UUID is given, and some OST matches,
5104 if (param->fp_obd_index != OBD_NOT_FOUND ||
5105 param->fp_mdt_index != OBD_NOT_FOUND) {
5106 if (param->fp_obd_uuid) {
5107 if (check_obd_match(param)) {
5109 * If no mdtuuid is given, we are done.
5110 * Otherwise, fall through to the mdtuuid
5113 if (!param->fp_mdt_uuid)
5120 if (param->fp_mdt_uuid) {
5121 if (check_mdt_match(param))
5128 if (param->fp_check_uid) {
5129 if (lmd->lmd_stx.stx_uid == param->fp_uid) {
5130 if (param->fp_exclude_uid)
5133 if (!param->fp_exclude_uid)
5138 if (param->fp_check_gid) {
5139 if (lmd->lmd_stx.stx_gid == param->fp_gid) {
5140 if (param->fp_exclude_gid)
5143 if (!param->fp_exclude_gid)
5148 if (param->fp_check_projid) {
5152 fd = open(path, O_RDONLY);
5155 ret = fget_projid(fd, &projid);
5160 if (projid == param->fp_projid) {
5161 if (param->fp_exclude_projid)
5164 if (!param->fp_exclude_projid)
5169 if (param->fp_check_pool) {
5170 decision = find_check_pool(param);
5175 if (param->fp_check_comp_count || param->fp_check_comp_flags ||
5176 param->fp_check_comp_start || param->fp_check_comp_end) {
5177 decision = find_check_comp_options(param);
5182 if (param->fp_check_mirror_count || param->fp_check_mirror_state) {
5183 decision = find_check_mirror_options(param);
5188 /* Check the time on mds. */
5190 if (param->fp_atime || param->fp_mtime || param->fp_ctime) {
5193 for_mds = lustre_fs ?
5194 (S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) : 0;
5195 decision = find_time_check(param, for_mds);
5200 if (param->fp_btime) {
5201 if (!(lmd->lmd_stx.stx_mask & STATX_BTIME)) {
5206 decision = find_value_cmp(lmd->lmd_stx.stx_btime.tv_sec,
5207 param->fp_btime, param->fp_bsign,
5208 param->fp_exclude_btime,
5209 param->fp_time_margin, 0);
5214 if (param->fp_newerxy) {
5217 for_mds = lustre_fs ?
5218 (S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) : 0;
5219 decision = find_newerxy_check(param, for_mds, true);
5228 flags = param->fp_lmd->lmd_flags;
5229 if (param->fp_check_size &&
5230 ((S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) ||
5231 S_ISDIR(lmd->lmd_stx.stx_mode)) &&
5232 !(flags & OBD_MD_FLSIZE ||
5233 (param->fp_lazy && flags & OBD_MD_FLLAZYSIZE)))
5236 if (param->fp_check_blocks &&
5237 ((S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) ||
5238 S_ISDIR(lmd->lmd_stx.stx_mode)) &&
5239 !(flags & OBD_MD_FLBLOCKS ||
5240 (param->fp_lazy && flags & OBD_MD_FLLAZYBLOCKS)))
5244 * If file still fits the request, ask ost for updated info.
5245 * The regular stat is almost of the same speed as some new
5246 * 'glimpse-size-ioctl'.
5252 * For regular files with the stripe the decision may have not
5253 * been taken yet if *time or size is to be checked.
5255 if (param->fp_obd_index != OBD_NOT_FOUND)
5256 print_failed_tgt(param, path, LL_STATFS_LOV);
5258 if (param->fp_mdt_index != OBD_NOT_FOUND)
5259 print_failed_tgt(param, path, LL_STATFS_LMV);
5262 ret = fstat_f(d, &st);
5263 else if (de != NULL)
5264 ret = fstatat_f(p, de->d_name, &st,
5265 AT_SYMLINK_NOFOLLOW);
5267 ret = lstat_f(path, &st);
5270 if (errno == ENOENT) {
5271 llapi_error(LLAPI_MSG_ERROR, -ENOENT,
5272 "warning: %s: %s does not exist",
5277 llapi_error(LLAPI_MSG_ERROR, ret,
5278 "%s: stat on %s failed",
5284 convert_lmd_statx(param->fp_lmd, &st, true);
5285 /* Check the time on osc. */
5286 decision = find_time_check(param, 0);
5290 if (param->fp_newerxy) {
5291 decision = find_newerxy_check(param, 0, false);
5301 if (param->fp_check_size) {
5302 decision = find_value_cmp(lmd->lmd_stx.stx_size,
5304 param->fp_size_sign,
5305 param->fp_exclude_size,
5306 param->fp_size_units, 0);
5311 if (param->fp_check_blocks) { /* convert st_blocks to bytes */
5312 decision = find_value_cmp(lmd->lmd_stx.stx_blocks * 512,
5314 param->fp_blocks_sign,
5315 param->fp_exclude_blocks,
5316 param->fp_blocks_units, 0);
5322 llapi_printf(LLAPI_MSG_NORMAL, "%s", path);
5323 if (param->fp_zero_end)
5324 llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0');
5326 llapi_printf(LLAPI_MSG_NORMAL, "\n");
5330 /* Do not get down anymore? */
5331 if (param->fp_depth == param->fp_max_depth) {
5342 static int cb_migrate_mdt_init(char *path, int p, int *dp,
5343 void *param_data, struct dirent64 *de)
5345 struct find_param *param = (struct find_param *)param_data;
5346 struct lmv_user_md *lmu = param->fp_lmv_md;
5348 char raw[MAX_IOC_BUFLEN] = {'\0'};
5350 struct obd_ioctl_data data = { 0 };
5356 if (p == -1 && dp == NULL)
5362 if (dp != NULL && *dp != -1)
5366 tmp_p = open_parent(path);
5370 llapi_error(LLAPI_MSG_ERROR, ret,
5371 "can not open %s", path);
5376 path_copy = strdup(path);
5377 filename = basename(path_copy);
5379 data.ioc_inlbuf1 = (char *)filename;
5380 data.ioc_inllen1 = strlen(filename) + 1;
5381 data.ioc_inlbuf2 = (char *)lmu;
5382 data.ioc_inllen2 = lmv_user_md_size(lmu->lum_stripe_count,
5384 ret = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
5386 llapi_error(LLAPI_MSG_ERROR, ret,
5387 "%s: error packing ioctl data", __func__);
5392 ret = ioctl(tmp_p, LL_IOC_MIGRATE, rawbuf);
5394 if (errno == EBUSY && !retry) {
5396 * because migrate may not be able to lock all involved
5397 * objects in order, for some of them it try lock, while
5398 * there may be conflicting COS locks and cause migrate
5399 * fail with EBUSY, hope a sync() could cause
5400 * transaction commit and release these COS locks.
5405 } else if (errno == EALREADY) {
5406 if (param->fp_verbose & VERBOSE_DETAIL)
5407 llapi_printf(LLAPI_MSG_NORMAL,
5408 "%s migrated to MDT%d already\n",
5409 path, lmu->lum_stripe_offset);
5413 llapi_error(LLAPI_MSG_ERROR, ret, "%s migrate failed",
5417 } else if (param->fp_verbose & VERBOSE_DETAIL) {
5418 llapi_printf(LLAPI_MSG_NORMAL,
5419 "migrate %s to MDT%d stripe count %d\n",
5420 path, lmu->lum_stripe_offset,
5421 lmu->lum_stripe_count);
5427 * If the directory is being migration, we need
5428 * close the directory after migration,
5429 * so the old directory cache will be cleanup
5430 * on the client side, and re-open to get the
5431 * new directory handle
5433 *dp = open(path, O_RDONLY|O_NDELAY|O_DIRECTORY);
5436 llapi_error(LLAPI_MSG_ERROR, ret,
5437 "%s: Failed to open '%s'", __func__, path);
5449 /* dir migration finished, shrink its stripes */
5450 static int cb_migrate_mdt_fini(char *path, int p, int *dp, void *data,
5451 struct dirent64 *de)
5453 struct find_param *param = data;
5454 struct lmv_user_md *lmu = param->fp_lmv_md;
5455 int lmulen = lmv_user_md_size(lmu->lum_stripe_count, lmu->lum_magic);
5458 if (de && de->d_type != DT_DIR)
5463 * close it before setxattr because the latter may destroy the
5464 * original object, and cause close fail.
5472 ret = setxattr(path, XATTR_NAME_LMV, lmu, lmulen, 0);
5473 if (ret == -EALREADY)
5476 cb_common_fini(path, p, dp, data, de);
5480 int llapi_migrate_mdt(char *path, struct find_param *param)
5482 return param_callback(path, cb_migrate_mdt_init, cb_migrate_mdt_fini,
5486 int llapi_mv(char *path, struct find_param *param)
5488 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 59, 0)
5489 static bool printed;
5492 llapi_error(LLAPI_MSG_ERROR, -ESTALE,
5493 "%s() is deprecated, use llapi_migrate_mdt() instead",
5498 return llapi_migrate_mdt(path, param);
5501 int llapi_find(char *path, struct find_param *param)
5503 return param_callback(path, cb_find_init, cb_common_fini, param);
5507 * Get MDT number that the file/directory inode referenced
5508 * by the open fd resides on.
5509 * Return 0 and mdtidx on success, or -ve errno.
5511 int llapi_file_fget_mdtidx(int fd, int *mdtidx)
5513 if (ioctl(fd, LL_IOC_GET_MDTIDX, mdtidx) < 0)
5518 static int cb_get_mdt_index(char *path, int p, int *dp, void *data,
5519 struct dirent64 *de)
5521 struct find_param *param = (struct find_param *)data;
5522 int d = dp == NULL ? -1 : *dp;
5526 if (p == -1 && d == -1)
5530 ret = llapi_file_fget_mdtidx(d, &mdtidx);
5531 } else /* if (p != -1) */ {
5534 fd = open(path, O_RDONLY | O_NOCTTY);
5536 ret = llapi_file_fget_mdtidx(fd, &mdtidx);
5544 if (ret == -ENODATA) {
5545 if (!param->fp_obd_uuid)
5546 llapi_printf(LLAPI_MSG_NORMAL,
5547 "'%s' has no stripe info\n", path);
5549 } else if (ret == -ENOENT) {
5550 llapi_error(LLAPI_MSG_WARN, ret,
5551 "warning: %s: '%s' does not exist",
5554 } else if (ret == -ENOTTY) {
5555 llapi_error(LLAPI_MSG_ERROR, ret,
5556 "%s: '%s' not on a Lustre fs",
5559 llapi_error(LLAPI_MSG_ERROR, ret,
5560 "error: %s: '%s' failed get_mdtidx",
5566 if (param->fp_quiet || !(param->fp_verbose & VERBOSE_DETAIL))
5567 llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx);
5569 llapi_printf(LLAPI_MSG_NORMAL, "%s\nmdt_index:\t%d\n",
5573 /* Do not go down anymore? */
5574 if (param->fp_depth == param->fp_max_depth)
5582 static int cb_getstripe(char *path, int p, int *dp, void *data,
5583 struct dirent64 *de)
5585 struct find_param *param = (struct find_param *)data;
5586 int d = dp == NULL ? -1 : *dp;
5589 if (p == -1 && d == -1)
5592 if (param->fp_obd_uuid) {
5593 param->fp_quiet = 1;
5594 ret = setup_obd_uuid(d != -1 ? d : p, path, param);
5599 if (d != -1 && (param->fp_get_lmv || param->fp_get_default_lmv))
5600 ret = cb_get_dirstripe(path, &d, param);
5602 (p != -1 && !param->fp_get_lmv && !param->fp_get_default_lmv))
5603 ret = get_lmd_info_fd(path, p, d, ¶m->fp_lmd->lmd_lmm,
5604 param->fp_lum_size, GET_LMD_STRIPE);
5605 else if (d == -1 && (param->fp_get_lmv || param->fp_get_default_lmv)) {
5606 /* in case of a dangling or valid faked symlink dir, opendir()
5607 * should have return either EINVAL or ENOENT, so let's try
5608 * to get LMV just in case, and by opening it as a file but
5609 * with O_NOFOLLOW ...
5611 int fd = open(path, O_RDONLY | O_NOFOLLOW);
5615 ret = cb_get_dirstripe(path, &fd, param);
5617 llapi_lov_dump_user_lmm(param, path, LDF_IS_DIR);
5624 if (errno == ENODATA && d != -1) {
5626 * We need to "fake" the "use the default" values
5627 * since the lmm struct is zeroed out at this point.
5628 * The magic needs to be set in order to satisfy
5629 * a check later on in the code path.
5630 * The object_seq needs to be set for the "(Default)"
5631 * prefix to be displayed.
5633 if (param->fp_get_default_lmv) {
5634 struct lmv_user_md *lum = param->fp_lmv_md;
5636 lum->lum_magic = LMV_USER_MAGIC;
5637 lum->lum_stripe_count = 0;
5638 lum->lum_stripe_offset = LMV_OFFSET_DEFAULT;
5640 } else if (param->fp_get_lmv) {
5641 struct lmv_user_md *lum = param->fp_lmv_md;
5644 ret = llapi_file_fget_mdtidx(d, &mdtidx);
5647 lum->lum_magic = LMV_MAGIC_V1;
5648 lum->lum_stripe_count = 0;
5649 lum->lum_stripe_offset = mdtidx;
5652 struct lov_user_md *lmm =
5653 ¶m->fp_lmd->lmd_lmm;
5655 lmm->lmm_magic = LOV_USER_MAGIC_V1;
5657 ostid_set_seq(&lmm->lmm_oi,
5658 FID_SEQ_LOV_DEFAULT);
5659 lmm->lmm_stripe_count = 0;
5660 lmm->lmm_stripe_size = 0;
5661 lmm->lmm_stripe_offset = -1;
5664 } else if (errno == ENODATA && p != -1) {
5665 if (!param->fp_obd_uuid && !param->fp_mdt_uuid)
5666 llapi_printf(LLAPI_MSG_NORMAL,
5667 "%s has no stripe info\n", path);
5669 } else if (errno == ENOENT) {
5670 llapi_error(LLAPI_MSG_WARN, -ENOENT,
5671 "warning: %s: %s does not exist",
5674 } else if (errno == ENOTTY) {
5676 llapi_error(LLAPI_MSG_ERROR, ret,
5677 "%s: '%s' not on a Lustre fs?",
5682 llapi_error(LLAPI_MSG_ERROR, ret,
5683 "error: %s: %s failed for %s",
5685 "LL_IOC_LOV_GETSTRIPE" :
5686 "IOC_MDC_GETFILESTRIPE", path);
5693 if (!(param->fp_verbose & VERBOSE_MDTINDEX))
5694 llapi_lov_dump_user_lmm(param, path, d != -1 ? LDF_IS_DIR : 0);
5697 /* Do not get down anymore? */
5698 if (param->fp_depth == param->fp_max_depth)
5706 int llapi_getstripe(char *path, struct find_param *param)
5708 return param_callback(path, (param->fp_verbose & VERBOSE_MDTINDEX) ?
5709 cb_get_mdt_index : cb_getstripe,
5710 cb_common_fini, param);
5713 int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
5714 struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
5716 char raw[MAX_IOC_BUFLEN] = {'\0'};
5718 struct obd_ioctl_data data = { 0 };
5721 data.ioc_inlbuf1 = (char *)&type;
5722 data.ioc_inllen1 = sizeof(__u32);
5723 data.ioc_inlbuf2 = (char *)&index;
5724 data.ioc_inllen2 = sizeof(__u32);
5725 data.ioc_pbuf1 = (char *)stat_buf;
5726 data.ioc_plen1 = sizeof(struct obd_statfs);
5727 data.ioc_pbuf2 = (char *)uuid_buf;
5728 data.ioc_plen2 = sizeof(struct obd_uuid);
5730 rc = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
5732 llapi_error(LLAPI_MSG_ERROR, rc,
5733 "%s: error packing ioctl data", __func__);
5737 rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
5739 return rc < 0 ? -errno : 0;
5742 int llapi_obd_statfs(char *path, __u32 type, __u32 index,
5743 struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
5748 fd = open(path, O_RDONLY);
5751 llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'",
5754 * If we can't even open a file on the filesystem (e.g. with
5755 * -ESHUTDOWN), force caller to exit or it will loop forever.
5760 rc = llapi_obd_fstatfs(fd, type, index, stat_buf, uuid_buf);
5767 #define MAX_STRING_SIZE 128
5769 int llapi_ping(char *obd_type, char *obd_name)
5771 int flags = O_RDONLY;
5772 char buf[1] = { 0 };
5776 rc = cfs_get_param_paths(&path, "%s/%s/ping",
5777 obd_type, obd_name);
5781 fd = open(path.gl_pathv[0], flags);
5783 if (errno == EACCES && flags == O_RDONLY) {
5788 llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s",
5793 if (flags == O_RDONLY)
5794 rc = read(fd, buf, sizeof(buf));
5796 rc = write(fd, buf, sizeof(buf));
5804 cfs_free_param_data(&path);
5808 int llapi_target_iterate(int type_num, char **obd_type,
5809 void *args, llapi_cb_t cb)
5815 for (i = 0; i < type_num; i++) {
5818 rc = cfs_get_param_paths(¶m, "%s/*/uuid", obd_type[i]);
5822 for (j = 0; j < param.gl_pathc; j++) {
5823 char obd_uuid[UUID_MAX + 1];
5827 fp = fopen(param.gl_pathv[j], "r");
5830 llapi_error(LLAPI_MSG_ERROR, rc,
5831 "error: opening '%s'",
5836 if (fgets(obd_uuid, sizeof(obd_uuid), fp) == NULL) {
5838 llapi_error(LLAPI_MSG_ERROR, rc,
5839 "error: reading '%s'",
5844 /* Extract the obd_name from the sysfs path.
5845 * 'topsysfs'/fs/lustre/'obd_type'/'obd_name'.
5847 obd_name = strstr(param.gl_pathv[j], "/fs/lustre/");
5853 /* skip /fs/lustre/'obd_type'/ */
5854 obd_name += strlen(obd_type[i]) + 12;
5855 /* chop off after obd_name */
5856 ptr = strrchr(obd_name, '/');
5860 cb(obd_type[i], obd_name, obd_uuid, args);
5869 cfs_free_param_data(¶m);
5873 static void do_target_check(char *obd_type_name, char *obd_name,
5874 char *obd_uuid, void *args)
5878 rc = llapi_ping(obd_type_name, obd_name);
5880 llapi_printf(LLAPI_MSG_NORMAL, "%s inactive.\n", obd_name);
5882 llapi_error(LLAPI_MSG_ERROR, rc, "error: check '%s'", obd_name);
5884 llapi_printf(LLAPI_MSG_NORMAL, "%s active.\n", obd_name);
5887 int llapi_target_check(int type_num, char **obd_type, char *dir)
5889 return llapi_target_iterate(type_num, obd_type, NULL, do_target_check);
5892 #undef MAX_STRING_SIZE
5894 /* Is this a lustre fs? */
5895 int llapi_is_lustre_mnttype(const char *type)
5897 return strcmp(type, "lustre") == 0 || strcmp(type, "lustre_tgt") == 0;
5900 /* Is this a lustre client fs? */
5901 int llapi_is_lustre_mnt(struct mntent *mnt)
5903 return (llapi_is_lustre_mnttype(mnt->mnt_type) &&
5904 strstr(mnt->mnt_fsname, ":/") != NULL);
5907 int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
5909 char fsname[PATH_MAX + 1];
5913 rc = llapi_search_fsname(mnt, fsname);
5917 root = open(mnt, O_RDONLY | O_DIRECTORY);
5920 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", mnt);
5924 rc = ioctl(root, OBD_IOC_QUOTACTL, qctl);
5927 if (rc == -ENOENT && LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd))
5928 llapi_error(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, rc,
5929 "Cannot find pool '%s'", qctl->qc_poolname);
5935 int llapi_get_connect_flags(const char *mnt, __u64 *flags)
5940 root = open(mnt, O_RDONLY | O_DIRECTORY);
5943 llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
5947 rc = ioctl(root, LL_IOC_GET_CONNECT_FLAGS, flags);
5950 llapi_error(LLAPI_MSG_ERROR, rc,
5951 "ioctl on %s for getting connect flags failed", mnt);
5958 * Flush cached pages from all clients.
5960 * \param fd File descriptor
5964 int llapi_file_flush(int fd)
5968 return llapi_get_data_version(fd, &dv, LL_DV_WR_FLUSH);