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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/utils/liblustreapi.c
34 * Author: Peter J. Braam <braam@clusterfs.com>
35 * Author: Phil Schwan <phil@clusterfs.com>
36 * Author: Robert Read <rread@clusterfs.com>
50 #include <sys/ioctl.h>
57 #include <sys/statfs.h>
58 #include <sys/syscall.h>
60 #include <sys/types.h>
61 #include <sys/xattr.h>
62 #include <sys/sysmacros.h>
65 #include <libgen.h> /* for dirname() */
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"
84 static int llapi_msg_level = LLAPI_MSG_MAX;
85 const char *liblustreapi_cmd;
87 char *mdt_hash_name[] = { "none",
88 LMV_HASH_NAME_ALL_CHARS,
89 LMV_HASH_NAME_FNV_1A_64,
93 struct lustre_foreign_type lu_foreign_types[] = {
94 {.lft_type = LU_FOREIGN_TYPE_NONE, .lft_name = "none"},
95 {.lft_type = LU_FOREIGN_TYPE_DAOS, .lft_name = "daos"},
96 /* must be the last element */
97 {.lft_type = LU_FOREIGN_TYPE_UNKNOWN, .lft_name = NULL}
98 /* array max dimension must be <= UINT32_MAX */
101 void llapi_msg_set_level(int level)
103 /* ensure level is in the good range */
104 if (level < LLAPI_MSG_OFF)
105 llapi_msg_level = LLAPI_MSG_OFF;
106 else if (level > LLAPI_MSG_MAX)
107 llapi_msg_level = LLAPI_MSG_MAX;
109 llapi_msg_level = level;
112 int llapi_msg_get_level(void)
114 return llapi_msg_level;
117 void llapi_set_command_name(const char *cmd)
119 liblustreapi_cmd = cmd;
122 void llapi_clear_command_name(void)
124 liblustreapi_cmd = NULL;
127 static void error_callback_default(enum llapi_message_level level, int err,
128 const char *fmt, va_list ap)
130 bool has_nl = strchr(fmt, '\n') != NULL;
132 if (liblustreapi_cmd != NULL)
133 fprintf(stderr, "%s %s: ", program_invocation_short_name,
136 fprintf(stderr, "%s: ", program_invocation_short_name);
139 if (level & LLAPI_MSG_NO_ERRNO) {
140 vfprintf(stderr, fmt, ap);
142 fprintf(stderr, "\n");
146 /* Remove trailing linefeed so error string can be appended.
147 * @fmt is a const string, so we can't modify it directly.
149 if (has_nl && (newfmt = strdup(fmt)))
150 *strrchr(newfmt, '\n') = '\0';
152 newfmt = (char *)fmt;
154 vfprintf(stderr, newfmt, ap);
157 fprintf(stderr, ": %s (%d)\n", strerror(err), err);
161 static void info_callback_default(enum llapi_message_level level, int err,
162 const char *fmt, va_list ap)
165 if (liblustreapi_cmd != NULL) {
166 fprintf(stdout, "%s %s: ",
167 program_invocation_short_name,
170 fprintf(stdout, "%s: ", program_invocation_short_name);
173 vfprintf(stdout, fmt, ap);
176 static llapi_log_callback_t llapi_error_callback = error_callback_default;
177 static llapi_log_callback_t llapi_info_callback = info_callback_default;
180 /* llapi_error will preserve errno */
181 void llapi_error(enum llapi_message_level level, int err, const char *fmt, ...)
184 int tmp_errno = errno;
186 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
190 llapi_error_callback(level, abs(err), fmt, args);
195 /* llapi_printf will preserve errno */
196 void llapi_printf(enum llapi_message_level level, const char *fmt, ...)
199 int tmp_errno = errno;
201 if ((level & LLAPI_MSG_MASK) > llapi_msg_level)
205 llapi_info_callback(level, 0, fmt, args);
211 * Set a custom error logging function. Passing in NULL will reset the logging
212 * callback to its default value.
214 * This function returns the value of the old callback.
216 llapi_log_callback_t llapi_error_callback_set(llapi_log_callback_t cb)
218 llapi_log_callback_t old = llapi_error_callback;
221 llapi_error_callback = cb;
223 llapi_error_callback = error_callback_default;
229 * Set a custom info logging function. Passing in NULL will reset the logging
230 * callback to its default value.
232 * This function returns the value of the old callback.
234 llapi_log_callback_t llapi_info_callback_set(llapi_log_callback_t cb)
236 llapi_log_callback_t old = llapi_info_callback;
239 llapi_info_callback = cb;
241 llapi_info_callback = info_callback_default;
247 * size_units is to be initialized (or zeroed) by caller.
249 int llapi_parse_size(const char *optarg, unsigned long long *size,
250 unsigned long long *size_units, int bytes_spec)
253 char *argbuf = (char *)optarg;
254 unsigned long long frac = 0, frac_d = 1;
256 if (strncmp(optarg, "-", 1) == 0)
259 if (*size_units == 0)
262 *size = strtoull(argbuf, &end, 0);
263 if (end != NULL && *end == '.') {
267 frac = strtoull(argbuf, &end, 10);
268 /* count decimal places */
269 for (i = 0; i < (end - argbuf); i++)
274 if ((*end == 'b') && *(end + 1) == '\0' &&
275 (*size & (~0ULL << (64 - 9))) == 0 &&
277 *size_units = 1 << 9;
278 } else if ((*end == 'b') &&
279 *(end + 1) == '\0' &&
282 } else if ((*end == 'k' || *end == 'K') &&
283 *(end + 1) == '\0' &&
284 (*size & (~0ULL << (64 - 10))) == 0) {
285 *size_units = 1 << 10;
286 } else if ((*end == 'm' || *end == 'M') &&
287 *(end + 1) == '\0' &&
288 (*size & (~0ULL << (64 - 20))) == 0) {
289 *size_units = 1 << 20;
290 } else if ((*end == 'g' || *end == 'G') &&
291 *(end + 1) == '\0' &&
292 (*size & (~0ULL << (64 - 30))) == 0) {
293 *size_units = 1 << 30;
294 } else if ((*end == 't' || *end == 'T') &&
295 *(end + 1) == '\0' &&
296 (*size & (~0ULL << (64 - 40))) == 0) {
297 *size_units = 1ULL << 40;
298 } else if ((*end == 'p' || *end == 'P') &&
299 *(end + 1) == '\0' &&
300 (*size & (~0ULL << (64 - 50))) == 0) {
301 *size_units = 1ULL << 50;
302 } else if ((*end == 'e' || *end == 'E') &&
303 *(end + 1) == '\0' &&
304 (*size & (~0ULL << (64 - 60))) == 0) {
305 *size_units = 1ULL << 60;
310 *size = *size * *size_units + frac * *size_units / frac_d;
315 int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len)
317 struct obd_ioctl_data *overlay;
320 data->ioc_len = obd_ioctl_packlen(data);
321 data->ioc_version = OBD_IOCTL_VERSION;
323 if (*pbuf != NULL && data->ioc_len > max_len) {
324 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
325 "pbuf = %p, ioc_len = %u, max_len = %d",
326 *pbuf, data->ioc_len, max_len);
331 *pbuf = malloc(data->ioc_len);
336 overlay = (struct obd_ioctl_data *)*pbuf;
337 memcpy(*pbuf, data, sizeof(*data));
339 ptr = overlay->ioc_bulk;
340 if (data->ioc_inlbuf1) {
341 memcpy(ptr, data->ioc_inlbuf1, data->ioc_inllen1);
342 ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
345 if (data->ioc_inlbuf2) {
346 memcpy(ptr, data->ioc_inlbuf2, data->ioc_inllen2);
347 ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
350 if (data->ioc_inlbuf3) {
351 memcpy(ptr, data->ioc_inlbuf3, data->ioc_inllen3);
352 ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
355 if (data->ioc_inlbuf4) {
356 memcpy(ptr, data->ioc_inlbuf4, data->ioc_inllen4);
357 ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
363 int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
365 struct obd_ioctl_data *overlay;
371 overlay = (struct obd_ioctl_data *)pbuf;
373 /* Preserve the caller's buffer pointers */
374 overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
375 overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
376 overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
377 overlay->ioc_inlbuf4 = data->ioc_inlbuf4;
379 memcpy(data, pbuf, sizeof(*data));
381 ptr = overlay->ioc_bulk;
382 if (data->ioc_inlbuf1) {
383 memcpy(data->ioc_inlbuf1, ptr, data->ioc_inllen1);
384 ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
387 if (data->ioc_inlbuf2) {
388 memcpy(data->ioc_inlbuf2, ptr, data->ioc_inllen2);
389 ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
392 if (data->ioc_inlbuf3) {
393 memcpy(data->ioc_inlbuf3, ptr, data->ioc_inllen3);
394 ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
397 if (data->ioc_inlbuf4) {
398 memcpy(data->ioc_inlbuf4, ptr, data->ioc_inllen4);
399 ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
405 /* XXX: llapi_xxx() functions return negative values upon failure */
407 int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
408 int stripe_count, int stripe_pattern)
410 static int page_size;
413 if (page_size == 0) {
414 /* 64 KB is the largest common page size (on ia64/PPC/ARM),
415 * but check the local page size just in case. The page_size
416 * will not change for the lifetime of this process at least.
418 page_size = LOV_MIN_STRIPE_SIZE;
419 if (getpagesize() > page_size) {
420 page_size = getpagesize();
421 llapi_err_noerrno(LLAPI_MSG_WARN,
422 "warning: page size (%u) larger than expected (%u)",
423 page_size, LOV_MIN_STRIPE_SIZE);
426 if (!llapi_stripe_size_is_aligned(stripe_size)) {
428 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %llu, "
429 "must be an even multiple of %d bytes",
430 (unsigned long long)stripe_size, page_size);
433 if (!llapi_stripe_index_is_valid(stripe_offset)) {
435 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
439 if (!llapi_stripe_count_is_valid(stripe_count)) {
441 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
445 if (llapi_stripe_size_is_too_big(stripe_size)) {
447 llapi_error(LLAPI_MSG_ERROR, rc,
448 "error: stripe size '%llu' over 4GB limit",
449 (unsigned long long)stripe_size);
458 int llapi_dir_stripe_limit_check(int stripe_offset, int stripe_count,
463 if (!llapi_dir_stripe_index_is_valid(stripe_offset)) {
465 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
469 if (!llapi_dir_stripe_count_is_valid(stripe_count)) {
471 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
476 if (!llapi_dir_hash_type_is_valid(hash_type)) {
478 llapi_error(LLAPI_MSG_ERROR, rc, "error: bad hash type %d",
486 * Trim a trailing newline from a string, if it exists.
488 int llapi_chomp_string(char *buf)
504 * Wrapper to grab parameter settings for lov.*-clilov-*.* values
506 static int get_param_lov(const char *path, const char *param,
507 char *buf, size_t buf_size)
509 struct obd_uuid uuid;
512 rc = llapi_file_get_lov_uuid(path, &uuid);
516 return get_lustre_param_value("lov", uuid.uuid, FILTER_BY_EXACT, param,
521 * Wrapper to grab parameter settings for lmv.*-clilov-*.* values
523 static int get_param_lmv(const char *path, const char *param,
524 char *buf, size_t buf_size)
526 struct obd_uuid uuid;
529 rc = llapi_file_get_lmv_uuid(path, &uuid);
533 return get_lustre_param_value("lmv", uuid.uuid, FILTER_BY_EXACT, param,
537 static int get_mds_md_size(const char *path)
539 char buf[PATH_MAX], inst[PATH_MAX];
540 int md_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
543 rc = llapi_getname(path, inst, sizeof(inst));
547 /* Get the max ea size from llite parameters. */
548 rc = get_lustre_param_value("llite", inst, FILTER_BY_EXACT,
549 "max_easize", buf, sizeof(buf));
555 return rc > 0 ? rc : md_size;
558 int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize)
560 return get_param_lmv(path, "uuid", buf, bufsize);
564 * Open a Lustre file.
566 * \param name the name of the file to be opened
567 * \param flags access mode, see flags in open(2)
568 * \param mode permission of the file if it is created, see mode in open(2)
569 * \param param stripe pattern of the newly created file
571 * \retval file descriptor of opened file
572 * \retval negative errno on failure
574 int llapi_file_open_param(const char *name, int flags, mode_t mode,
575 const struct llapi_stripe_param *param)
577 char fsname[MAX_OBD_NAME + 1] = { 0 };
578 char *pool_name = param->lsp_pool;
579 struct lov_user_md *lum = NULL;
580 size_t lum_size = sizeof(*lum);
583 /* Make sure we are on a Lustre file system */
584 rc = llapi_search_fsname(name, fsname);
586 llapi_error(LLAPI_MSG_ERROR, rc,
587 "'%s' is not on a Lustre filesystem",
592 /* Check if the stripe pattern is sane. */
593 rc = llapi_stripe_limit_check(param->lsp_stripe_size,
594 param->lsp_stripe_offset,
595 param->lsp_stripe_count,
596 param->lsp_stripe_pattern);
600 /* Make sure we have a good pool */
601 if (pool_name != NULL) {
602 /* in case user gives the full pool name <fsname>.<poolname>,
603 * strip the fsname */
604 char *ptr = strchr(pool_name, '.');
607 if (strcmp(pool_name, fsname) != 0) {
609 llapi_err_noerrno(LLAPI_MSG_ERROR,
610 "Pool '%s' is not on filesystem '%s'",
617 /* Make sure the pool exists and is non-empty */
618 rc = llapi_search_ost(fsname, pool_name, NULL);
620 char *err = rc == 0 ? "has no OSTs" : "does not exist";
622 llapi_err_noerrno(LLAPI_MSG_ERROR, "pool '%s.%s' %s",
623 fsname, pool_name, err);
627 lum_size = sizeof(struct lov_user_md_v3);
630 /* sanity check of target list */
631 if (param->lsp_is_specific) {
632 char ostname[MAX_OBD_NAME + 64];
636 for (i = 0; i < param->lsp_stripe_count; i++) {
637 snprintf(ostname, sizeof(ostname), "%s-OST%04x_UUID",
638 fsname, param->lsp_osts[i]);
639 rc = llapi_search_ost(fsname, pool_name, ostname);
644 llapi_error(LLAPI_MSG_ERROR, rc,
645 "%s: cannot find OST %s in %s",
652 /* Make sure stripe offset is in OST list. */
653 if (param->lsp_osts[i] == param->lsp_stripe_offset)
657 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
658 "%s: stripe offset '%d' is not in the "
660 __func__, param->lsp_stripe_offset);
664 lum_size = lov_user_md_size(param->lsp_stripe_count,
665 LOV_USER_MAGIC_SPECIFIC);
668 lum = calloc(1, lum_size);
673 fd = open(name, flags | O_LOV_DELAY_CREATE, mode);
675 if (errno == EISDIR && !(flags & O_DIRECTORY)) {
676 flags = O_DIRECTORY | O_RDONLY;
683 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
688 /* Initialize IOCTL striping pattern structure */
689 lum->lmm_magic = LOV_USER_MAGIC_V1;
690 lum->lmm_pattern = param->lsp_stripe_pattern;
691 lum->lmm_stripe_size = param->lsp_stripe_size;
692 lum->lmm_stripe_count = param->lsp_stripe_count;
693 lum->lmm_stripe_offset = param->lsp_stripe_offset;
694 if (pool_name != NULL) {
695 struct lov_user_md_v3 *lumv3 = (void *)lum;
697 lumv3->lmm_magic = LOV_USER_MAGIC_V3;
698 strncpy(lumv3->lmm_pool_name, pool_name, LOV_MAXPOOLNAME);
700 if (param->lsp_is_specific) {
701 struct lov_user_md_v3 *lumv3 = (void *)lum;
704 lumv3->lmm_magic = LOV_USER_MAGIC_SPECIFIC;
705 if (pool_name == NULL) {
706 /* LOV_USER_MAGIC_SPECIFIC uses v3 format plus specified
707 * OST list, therefore if pool is not specified we have
708 * to pack a null pool name for placeholder. */
709 memset(lumv3->lmm_pool_name, 0, LOV_MAXPOOLNAME);
712 for (i = 0; i < param->lsp_stripe_count; i++)
713 lumv3->lmm_objects[i].l_ost_idx = param->lsp_osts[i];
716 if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, lum) != 0) {
717 char errmsg[512] = "stripe already set";
720 if (errno != EEXIST && errno != EALREADY)
721 strncpy(errmsg, strerror(errno), sizeof(errmsg) - 1);
722 if (rc == -EREMOTEIO)
723 snprintf(errmsg, sizeof(errmsg),
724 "inactive OST among your specified %d OST(s)",
725 param->lsp_stripe_count);
727 llapi_err_noerrno(LLAPI_MSG_ERROR,
728 "setstripe error for '%s': %s", name, errmsg);
739 int llapi_file_open_pool(const char *name, int flags, int mode,
740 unsigned long long stripe_size, int stripe_offset,
741 int stripe_count, int stripe_pattern, char *pool_name)
743 const struct llapi_stripe_param param = {
744 .lsp_stripe_size = stripe_size,
745 .lsp_stripe_count = stripe_count,
746 .lsp_stripe_pattern = stripe_pattern,
747 .lsp_stripe_offset = stripe_offset,
748 .lsp_pool = pool_name
750 return llapi_file_open_param(name, flags, mode, ¶m);
753 int llapi_file_open(const char *name, int flags, int mode,
754 unsigned long long stripe_size, int stripe_offset,
755 int stripe_count, int stripe_pattern)
757 return llapi_file_open_pool(name, flags, mode, stripe_size,
758 stripe_offset, stripe_count,
759 stripe_pattern, NULL);
762 int llapi_file_create_foreign(const char *name, mode_t mode, __u32 type,
763 __u32 flags, char *foreign_lov)
766 struct lov_foreign_md *lfm;
769 if (foreign_lov == NULL) {
771 llapi_error(LLAPI_MSG_ERROR, rc,
772 "foreign LOV EA content must be provided");
776 len = strlen(foreign_lov);
777 if (len > XATTR_SIZE_MAX - offsetof(struct lov_foreign_md, lfm_value) ||
780 llapi_error(LLAPI_MSG_ERROR, rc,
781 "foreign LOV EA size %zu (must be 0 < len < %zu)",
782 len, XATTR_SIZE_MAX -
783 offsetof(struct lov_foreign_md, lfm_value));
787 lfm = malloc(len + offsetof(struct lov_foreign_md, lfm_value));
790 llapi_error(LLAPI_MSG_ERROR, rc,
791 "failed to allocate lov_foreign_md");
795 fd = open(name, O_WRONLY|O_CREAT|O_LOV_DELAY_CREATE, mode);
798 llapi_error(LLAPI_MSG_ERROR, fd, "open '%s' failed", name);
802 lfm->lfm_magic = LOV_USER_MAGIC_FOREIGN;
803 lfm->lfm_length = len;
804 lfm->lfm_type = type;
805 lfm->lfm_flags = flags;
806 memcpy(lfm->lfm_value, foreign_lov, len);
808 if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, lfm) != 0) {
809 char *errmsg = "stripe already set";
813 errmsg = "not on a Lustre filesystem";
814 else if (errno == EEXIST || errno == EALREADY)
815 errmsg = "stripe already set";
817 errmsg = strerror(errno);
819 llapi_err_noerrno(LLAPI_MSG_ERROR,
820 "setstripe error for '%s': %s", name, errmsg);
836 int llapi_file_create(const char *name, unsigned long long stripe_size,
837 int stripe_offset, int stripe_count, int stripe_pattern)
841 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
842 stripe_offset, stripe_count, stripe_pattern,
851 int llapi_file_create_pool(const char *name, unsigned long long stripe_size,
852 int stripe_offset, int stripe_count,
853 int stripe_pattern, char *pool_name)
857 fd = llapi_file_open_pool(name, O_CREAT | O_WRONLY, 0644, stripe_size,
858 stripe_offset, stripe_count, stripe_pattern,
867 static int verify_dir_param(const char *name,
868 const struct llapi_stripe_param *param)
870 char fsname[MAX_OBD_NAME + 1] = { 0 };
871 char *pool_name = param->lsp_pool;
874 /* Make sure we are on a Lustre file system */
875 rc = llapi_search_fsname(name, fsname);
877 llapi_error(LLAPI_MSG_ERROR, rc,
878 "'%s' is not on a Lustre filesystem",
883 /* Check if the stripe pattern is sane. */
884 rc = llapi_dir_stripe_limit_check(param->lsp_stripe_offset,
885 param->lsp_stripe_count,
886 param->lsp_stripe_pattern);
890 /* Make sure we have a good pool */
891 if (pool_name != NULL) {
892 /* in case user gives the full pool name <fsname>.<poolname>,
893 * strip the fsname */
894 char *ptr = strchr(pool_name, '.');
898 if (strcmp(pool_name, fsname) != 0) {
900 llapi_err_noerrno(LLAPI_MSG_ERROR,
901 "Pool '%s' is not on filesystem '%s'",
908 /* Make sure the pool exists and is non-empty */
909 rc = llapi_search_tgt(fsname, pool_name, NULL, true);
911 char *err = rc == 0 ? "has no OSTs" : "does not exist";
913 llapi_err_noerrno(LLAPI_MSG_ERROR, "pool '%s.%s' %s",
914 fsname, pool_name, err);
919 /* sanity check of target list */
920 if (param->lsp_is_specific) {
921 char mdtname[MAX_OBD_NAME + 64];
925 for (i = 0; i < param->lsp_stripe_count; i++) {
926 snprintf(mdtname, sizeof(mdtname), "%s-MDT%04x_UUID",
927 fsname, param->lsp_tgts[i]);
928 rc = llapi_search_tgt(fsname, pool_name, mdtname, true);
933 llapi_error(LLAPI_MSG_ERROR, rc,
934 "%s: cannot find MDT %s in %s",
941 /* Make sure stripe offset is in MDT list. */
942 if (param->lsp_tgts[i] == param->lsp_stripe_offset)
946 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
947 "%s: stripe offset '%d' is not in the "
949 __func__, param->lsp_stripe_offset);
957 static inline void param2lmu(struct lmv_user_md *lmu,
958 const struct llapi_stripe_param *param)
960 lmu->lum_magic = param->lsp_is_specific ? LMV_USER_MAGIC_SPECIFIC :
962 lmu->lum_stripe_count = param->lsp_stripe_count;
963 lmu->lum_stripe_offset = param->lsp_stripe_offset;
964 lmu->lum_hash_type = param->lsp_stripe_pattern;
965 if (param->lsp_pool != NULL)
966 strncpy(lmu->lum_pool_name, param->lsp_pool, LOV_MAXPOOLNAME);
967 if (param->lsp_is_specific) {
970 for (i = 0; i < param->lsp_stripe_count; i++)
971 lmu->lum_objects[i].lum_mds = param->lsp_tgts[i];
975 int llapi_dir_set_default_lmv(const char *name,
976 const struct llapi_stripe_param *param)
978 struct lmv_user_md lmu = { 0 };
982 rc = verify_dir_param(name, param);
986 /* TODO: default lmv doesn't support specific targets yet */
987 if (param->lsp_is_specific)
990 param2lmu(&lmu, param);
992 fd = open(name, O_DIRECTORY | O_RDONLY);
995 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
999 rc = ioctl(fd, LL_IOC_LMV_SET_DEFAULT_STRIPE, &lmu);
1001 char *errmsg = "stripe already set";
1003 if (errno != EEXIST && errno != EALREADY)
1004 errmsg = strerror(errno);
1006 llapi_err_noerrno(LLAPI_MSG_ERROR,
1007 "default dirstripe error on '%s': %s",
1014 int llapi_dir_set_default_lmv_stripe(const char *name, int stripe_offset,
1015 int stripe_count, int stripe_pattern,
1016 const char *pool_name)
1018 const struct llapi_stripe_param param = {
1019 .lsp_stripe_count = stripe_count,
1020 .lsp_stripe_offset = stripe_offset,
1021 .lsp_stripe_pattern = stripe_pattern,
1022 .lsp_pool = (char *)pool_name
1025 return llapi_dir_set_default_lmv(name, ¶m);
1029 * Create a Lustre directory.
1031 * \param name the name of the directory to be created
1032 * \param mode permission of the file if it is created, see mode in open(2)
1033 * \param param stripe pattern of the newly created directory
1035 * \retval 0 on success
1036 * \retval negative errno on failure
1038 int llapi_dir_create(const char *name, mode_t mode,
1039 const struct llapi_stripe_param *param)
1041 struct lmv_user_md *lmu = NULL;
1043 struct obd_ioctl_data data = { 0 };
1046 char *dirpath = NULL;
1047 char *namepath = NULL;
1052 rc = verify_dir_param(name, param);
1056 lmu_size = lmv_user_md_size(param->lsp_stripe_count,
1057 param->lsp_is_specific ?
1058 LMV_USER_MAGIC_SPECIFIC :
1061 lmu = calloc(1, lmu_size);
1065 dirpath = strdup(name);
1071 namepath = strdup(name);
1078 param2lmu(lmu, param);
1080 filename = basename(namepath);
1081 dir = dirname(dirpath);
1083 data.ioc_inlbuf1 = (char *)filename;
1084 data.ioc_inllen1 = strlen(filename) + 1;
1085 data.ioc_inlbuf2 = (char *)lmu;
1086 data.ioc_inllen2 = lmu_size;
1087 data.ioc_type = mode;
1088 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1090 llapi_error(LLAPI_MSG_ERROR, rc,
1091 "error: LL_IOC_LMV_SETSTRIPE pack failed '%s'.",
1096 fd = open(dir, O_DIRECTORY | O_RDONLY);
1099 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
1103 if (ioctl(fd, LL_IOC_LMV_SETSTRIPE, buf)) {
1104 char *errmsg = "stripe already set";
1107 if (errno != EEXIST && errno != EALREADY)
1108 errmsg = strerror(errno);
1110 llapi_err_noerrno(LLAPI_MSG_ERROR,
1111 "dirstripe error on '%s': %s", name, errmsg);
1122 * Create a foreign directory.
1124 * \param name the name of the directory to be created
1125 * \param mode permission of the file if it is created, see mode in open(2)
1126 * \param type foreign type to be set in LMV EA
1127 * \param flags foreign flags to be set in LMV EA
1128 * \param value foreign pattern to be set in LMV EA
1130 * \retval 0 on success
1131 * \retval negative errno on failure
1133 int llapi_dir_create_foreign(const char *name, mode_t mode, __u32 type,
1134 __u32 flags, const char *value)
1136 struct lmv_foreign_md *lfm = NULL;
1137 size_t lfm_size, len;
1138 struct obd_ioctl_data data = { 0 };
1141 char *dirpath = NULL;
1142 char *namepath = NULL;
1147 len = strlen(value);
1148 if (len > XATTR_SIZE_MAX - offsetof(struct lmv_foreign_md, lfm_value) ||
1151 llapi_error(LLAPI_MSG_ERROR, rc,
1152 "invalid LOV EA length %zu (must be 0 < len < %zu)",
1153 len, XATTR_SIZE_MAX -
1154 offsetof(struct lmv_foreign_md, lfm_value));
1157 lfm_size = len + offsetof(struct lmv_foreign_md, lfm_value);
1158 lfm = calloc(1, lfm_size);
1162 dirpath = strdup(name);
1168 namepath = strdup(name);
1175 lfm->lfm_magic = LMV_MAGIC_FOREIGN;
1176 lfm->lfm_length = len;
1177 lfm->lfm_type = type;
1178 lfm->lfm_flags = flags;
1179 memcpy(lfm->lfm_value, value, len);
1181 filename = basename(namepath);
1182 dir = dirname(dirpath);
1184 data.ioc_inlbuf1 = (char *)filename;
1185 data.ioc_inllen1 = strlen(filename) + 1;
1186 data.ioc_inlbuf2 = (char *)lfm;
1187 data.ioc_inllen2 = lfm_size;
1188 data.ioc_type = mode;
1189 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
1191 llapi_error(LLAPI_MSG_ERROR, rc,
1192 "error: LL_IOC_LMV_SETSTRIPE pack failed '%s'.",
1197 fd = open(dir, O_DIRECTORY | O_RDONLY);
1200 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'", name);
1204 if (ioctl(fd, LL_IOC_LMV_SETSTRIPE, buf)) {
1205 char *errmsg = "stripe already set";
1208 if (errno != EEXIST && errno != EALREADY)
1209 errmsg = strerror(errno);
1211 llapi_err_noerrno(LLAPI_MSG_ERROR,
1212 "dirstripe error on '%s': %s", name, errmsg);
1222 int llapi_dir_create_pool(const char *name, int mode, int stripe_offset,
1223 int stripe_count, int stripe_pattern,
1224 const char *pool_name)
1226 const struct llapi_stripe_param param = {
1227 .lsp_stripe_count = stripe_count,
1228 .lsp_stripe_offset = stripe_offset,
1229 .lsp_stripe_pattern = stripe_pattern,
1230 .lsp_pool = (char *)pool_name
1233 return llapi_dir_create(name, mode, ¶m);
1236 int llapi_direntry_remove(char *dname)
1238 char *dirpath = NULL;
1239 char *namepath = NULL;
1245 dirpath = strdup(dname);
1246 namepath = strdup(dname);
1247 if (!dirpath || !namepath)
1250 filename = basename(namepath);
1252 dir = dirname(dirpath);
1254 fd = open(dir, O_DIRECTORY | O_RDONLY);
1257 llapi_error(LLAPI_MSG_ERROR, rc, "unable to open '%s'",
1262 if (ioctl(fd, LL_IOC_REMOVE_ENTRY, filename))
1263 llapi_error(LLAPI_MSG_ERROR, errno,
1264 "error on ioctl %#lx for '%s' (%d)",
1265 (long)LL_IOC_LMV_SETSTRIPE, filename, fd);
1275 * Find the fsname, the full path, and/or an open fd.
1276 * Either the fsname or path must not be NULL
1278 int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
1281 char buf[PATH_MAX], mntdir[PATH_MAX];
1282 char *ptr, *ptr_end;
1284 int idx = 0, len = 0, mntlen, fd;
1286 int fsnamelen, mountlen;
1288 /* get the mount point */
1289 fp = setmntent(PROC_MOUNTS, "r");
1292 llapi_error(LLAPI_MSG_ERROR, rc,
1293 "cannot retrieve filesystem mount point");
1297 if (getmntent_r(fp, &mnt, buf, sizeof(buf)) == NULL)
1300 if (!llapi_is_lustre_mnt(&mnt))
1303 if ((want & WANT_INDEX) && (idx++ != index))
1306 mntlen = strlen(mnt.mnt_dir);
1307 ptr = strchr(mnt.mnt_fsname, '/');
1308 while (ptr && *ptr == '/')
1310 /* thanks to the call to llapi_is_lustre_mnt() above,
1311 * we are sure that mnt.mnt_fsname contains ":/",
1312 * so ptr should never be NULL */
1316 while (*ptr_end != '/' && *ptr_end != '\0')
1319 /* Check the fsname for a match, if given */
1320 mountlen = ptr_end - ptr;
1321 if (!(want & WANT_FSNAME) && fsname != NULL &&
1322 (fsnamelen = strlen(fsname)) > 0 &&
1323 (fsnamelen != mountlen ||
1324 (strncmp(ptr, fsname, mountlen) != 0)))
1327 /* If the path isn't set return the first one we find */
1328 if (path == NULL || strlen(path) == 0) {
1329 strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
1330 mntdir[sizeof(mntdir) - 1] = '\0';
1331 if ((want & WANT_FSNAME) && fsname != NULL) {
1332 strncpy(fsname, ptr, mountlen);
1333 fsname[mountlen] = '\0';
1337 /* Otherwise find the longest matching path */
1338 } else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
1339 (strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
1340 strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
1341 mntdir[sizeof(mntdir) - 1] = '\0';
1343 if ((want & WANT_FSNAME) && fsname != NULL) {
1344 strncpy(fsname, ptr, mountlen);
1345 fsname[mountlen] = '\0';
1354 if ((want & WANT_PATH) && path != NULL) {
1355 strncpy(path, mntdir, PATH_MAX);
1356 path[strlen(mntdir)] = '\0';
1358 if (want & WANT_FD) {
1359 fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
1362 llapi_error(LLAPI_MSG_ERROR, rc,
1363 "cannot open '%s'", mntdir);
1369 } else if (want & WANT_ERROR)
1370 llapi_err_noerrno(LLAPI_MSG_ERROR,
1371 "'%s' not on a mounted Lustre filesystem",
1372 (want & WANT_PATH) ? fsname : path);
1377 * search lustre mounts
1379 * Calling this function will return to the user the mount point, mntdir, and
1380 * the file system name, fsname, if the user passed a buffer to this routine.
1382 * The user inputs are pathname and index. If the pathname is supplied then
1383 * the value of the index will be ignored. The pathname will return data if
1384 * the pathname is located on a lustre mount. Index is used to pick which
1385 * mount point you want in the case of multiple mounted lustre file systems.
1386 * See function lfs_osts in lfs.c for an example of the index use.
1388 int llapi_search_mounts(const char *pathname, int index, char *mntdir,
1391 int want = WANT_PATH, idx = -1;
1393 if (!pathname || pathname[0] == '\0') {
1397 strcpy(mntdir, pathname);
1400 want |= WANT_FSNAME;
1401 return get_root_path(want, fsname, NULL, mntdir, idx);
1404 /* Given a path, find the corresponding Lustre fsname */
1405 int llapi_search_fsname(const char *pathname, char *fsname)
1410 path = realpath(pathname, NULL);
1412 char tmp[PATH_MAX - 1];
1418 if (pathname[0] != '/') {
1419 /* Need an absolute path, but realpath() only works for
1420 * pathnames that actually exist. We go through the
1421 * extra hurdle of dirname(getcwd() + pathname) in
1422 * case the relative pathname contains ".." in it. */
1423 char realpath[PATH_MAX - 1];
1425 if (getcwd(realpath, sizeof(realpath) - 2) == NULL) {
1427 llapi_error(LLAPI_MSG_ERROR, rc,
1428 "cannot get current working directory");
1432 rc = snprintf(tmp, sizeof(tmp), "%s/", realpath);
1433 if (rc >= sizeof(tmp)) {
1435 llapi_error(LLAPI_MSG_ERROR, rc,
1436 "invalid parent path '%s'",
1442 rc = snprintf(buf, sizeof(buf), "%s%s", tmp, pathname);
1443 if (rc >= sizeof(buf)) {
1445 llapi_error(LLAPI_MSG_ERROR, rc,
1446 "invalid path '%s'", pathname);
1449 path = realpath(buf, NULL);
1451 ptr = strrchr(buf, '/');
1453 llapi_error(LLAPI_MSG_ERROR |
1454 LLAPI_MSG_NO_ERRNO, 0,
1455 "cannot resolve path '%s'",
1460 path = realpath(buf, NULL);
1463 llapi_error(LLAPI_MSG_ERROR, rc,
1464 "cannot resolve path '%s'",
1470 rc = get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL, path, -1);
1475 int llapi_search_rootpath(char *pathname, const char *fsname)
1477 /* pathname can be used as an argument by get_root_path(),
1478 * clear it for safety */
1480 return get_root_path(WANT_PATH, (char *)fsname, NULL, pathname, -1);
1484 * Get the list of pool members.
1485 * \param poolname string of format \<fsname\>.\<poolname\>
1486 * \param members caller-allocated array of char*
1487 * \param list_size size of the members array
1488 * \param buffer caller-allocated buffer for storing OST names
1489 * \param buffer_size size of the buffer
1491 * \return number of members retrieved for this pool
1492 * \retval -error failure
1494 int llapi_get_poolmembers(const char *poolname, char **members,
1495 int list_size, char *buffer, int buffer_size)
1497 char fsname[PATH_MAX];
1506 /* name is FSNAME.POOLNAME */
1507 if (strlen(poolname) >= sizeof(fsname))
1510 snprintf(fsname, sizeof(fsname), "%s", poolname);
1511 pool = strchr(fsname, '.');
1518 rc = poolpath(&pathname, fsname, NULL);
1520 llapi_error(LLAPI_MSG_ERROR, rc,
1521 "Lustre filesystem '%s' not found",
1526 llapi_printf(LLAPI_MSG_NORMAL, "Pool: %s.%s\n", fsname, pool);
1527 rc = snprintf(buf, sizeof(buf), "%s/%s", pathname.gl_pathv[0], pool);
1528 cfs_free_param_data(&pathname);
1529 if (rc >= sizeof(buf))
1531 fd = fopen(buf, "r");
1534 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open %s", buf);
1539 while (fgets(buf, sizeof(buf), fd) != NULL) {
1540 if (nb_entries >= list_size) {
1544 buf[sizeof(buf) - 1] = '\0';
1546 tmp = strchr(buf, '\n');
1549 if (used + strlen(buf) + 1 > buffer_size) {
1554 strcpy(buffer + used, buf);
1555 members[nb_entries] = buffer + used;
1556 used += strlen(buf) + 1;
1566 * Get the list of pools in a filesystem.
1567 * \param name filesystem name or path
1568 * \param poollist caller-allocated array of char*
1569 * \param list_size size of the poollist array
1570 * \param buffer caller-allocated buffer for storing pool names
1571 * \param buffer_size size of the buffer
1573 * \return number of pools retrieved for this filesystem
1574 * \retval -error failure
1576 int llapi_get_poollist(const char *name, char **poollist, int list_size,
1577 char *buffer, int buffer_size)
1583 struct dirent *pool;
1585 unsigned int nb_entries = 0;
1586 unsigned int used = 0;
1589 /* initialize output array */
1590 for (i = 0; i < list_size; i++)
1593 /* is name a pathname ? */
1594 ptr = strchr(name, '/');
1596 char fsname_buf[MAXNAMLEN];
1598 /* We will need fsname for printing later */
1599 rc = llapi_getname(name, fsname_buf, sizeof(fsname_buf));
1603 ptr = strrchr(fsname_buf, '-');
1607 fsname = strdup(fsname_buf);
1611 /* name is FSNAME */
1612 fsname = strdup(name);
1617 rc = poolpath(&pathname, fsname, NULL);
1619 llapi_error(LLAPI_MSG_ERROR, rc,
1620 "Lustre filesystem '%s' not found", name);
1624 dir = opendir(pathname.gl_pathv[0]);
1627 llapi_error(LLAPI_MSG_ERROR, rc,
1628 "Could not open pool list for '%s'",
1635 pool = readdir(dir);
1641 /* ignore . and .. */
1642 if (!strcmp(pool->d_name, ".") || !strcmp(pool->d_name, ".."))
1645 /* check output bounds */
1646 if (nb_entries >= list_size) {
1648 goto free_dir_no_msg;
1651 /* +2 for '.' and final '\0' */
1652 if (used + strlen(pool->d_name) + strlen(fsname) + 2
1655 goto free_dir_no_msg;
1658 sprintf(buffer + used, "%s.%s", fsname, pool->d_name);
1659 poollist[nb_entries] = buffer + used;
1660 used += strlen(pool->d_name) + strlen(fsname) + 2;
1666 llapi_error(LLAPI_MSG_ERROR, rc,
1667 "Error reading pool list for '%s'", name);
1669 llapi_printf(LLAPI_MSG_NORMAL, "Pools from %s:\n", fsname);
1674 cfs_free_param_data(&pathname);
1677 return rc != 0 ? rc : nb_entries;
1680 /* wrapper for lfs.c and obd.c */
1681 int llapi_poollist(const char *name)
1683 /* list of pool names (assume that pool count is smaller
1685 char **list, *buffer = NULL, *fsname = (char *)name;
1686 char *poolname = NULL, *tmp = NULL, data[16];
1687 enum param_filter type = FILTER_BY_PATH;
1688 int obdcount, bufsize, rc, nb, i;
1693 if (name[0] != '/') {
1694 fsname = strdup(name);
1698 poolname = strchr(fsname, '.');
1701 type = FILTER_BY_FS_NAME;
1704 rc = get_lustre_param_value("lov", fsname, type, "numobd",
1705 data, sizeof(data));
1708 obdcount = atoi(data);
1710 /* Allocate space for each fsname-OST0000_UUID, 1 per OST,
1711 * and also an array to store the pointers for all that
1712 * allocated space. */
1714 bufsize = sizeof(struct obd_uuid) * obdcount;
1715 buffer = realloc(tmp, bufsize + sizeof(*list) * obdcount);
1716 if (buffer == NULL) {
1720 list = (char **) (buffer + bufsize);
1723 /* name is a path or fsname */
1724 nb = llapi_get_poollist(name, list, obdcount,
1727 /* name is a pool name (<fsname>.<poolname>) */
1728 nb = llapi_get_poolmembers(name, list, obdcount,
1732 if (nb == -EOVERFLOW) {
1735 goto retry_get_pools;
1738 for (i = 0; i < nb; i++)
1739 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", list[i]);
1740 rc = (nb < 0 ? nb : 0);
1744 if (fsname != NULL && type == FILTER_BY_FS_NAME)
1749 typedef int (semantic_func_t)(char *path, DIR *parent, DIR **d,
1750 void *data, struct dirent64 *de);
1752 #define OBD_NOT_FOUND (-1)
1754 static void find_param_fini(struct find_param *param)
1756 if (param->fp_migrate)
1759 if (param->fp_obd_indexes) {
1760 free(param->fp_obd_indexes);
1761 param->fp_obd_indexes = NULL;
1764 if (param->fp_lmd) {
1765 free(param->fp_lmd);
1766 param->fp_lmd = NULL;
1769 if (param->fp_lmv_md) {
1770 free(param->fp_lmv_md);
1771 param->fp_lmv_md = NULL;
1775 static int common_param_init(struct find_param *param, char *path)
1777 int lum_size = get_mds_md_size(path);
1782 /* migrate has fp_lmv_md initialized outside */
1783 if (param->fp_migrate)
1786 if (lum_size < PATH_MAX + 1)
1787 lum_size = PATH_MAX + 1;
1789 param->fp_lum_size = lum_size;
1790 param->fp_lmd = calloc(1, offsetof(typeof(*param->fp_lmd), lmd_lmm) +
1792 if (param->fp_lmd == NULL) {
1793 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1794 "error: allocate %zu bytes for layout failed",
1795 sizeof(lstat_t) + param->fp_lum_size);
1799 param->fp_lmv_stripe_count = 256;
1800 param->fp_lmv_md = calloc(1,
1801 lmv_user_md_size(param->fp_lmv_stripe_count,
1802 LMV_USER_MAGIC_SPECIFIC));
1803 if (param->fp_lmv_md == NULL) {
1804 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1805 "error: allocation of %d bytes for ioctl",
1806 lmv_user_md_size(param->fp_lmv_stripe_count,
1807 LMV_USER_MAGIC_SPECIFIC));
1808 find_param_fini(param);
1812 param->fp_got_uuids = 0;
1813 param->fp_obd_indexes = NULL;
1814 param->fp_obd_index = OBD_NOT_FOUND;
1815 param->fp_mdt_index = OBD_NOT_FOUND;
1819 static int cb_common_fini(char *path, DIR *parent, DIR **dirp, void *data,
1820 struct dirent64 *de)
1822 struct find_param *param = data;
1828 /* set errno upon failure */
1829 static DIR *opendir_parent(const char *path)
1835 path_copy = strdup(path);
1836 if (path_copy == NULL)
1839 parent_path = dirname(path_copy);
1840 parent = opendir(parent_path);
1846 static int cb_get_dirstripe(char *path, DIR *d, struct find_param *param)
1851 param->fp_lmv_md->lum_stripe_count = param->fp_lmv_stripe_count;
1852 if (param->fp_get_default_lmv)
1853 param->fp_lmv_md->lum_magic = LMV_USER_MAGIC;
1855 param->fp_lmv_md->lum_magic = LMV_MAGIC_V1;
1857 ret = ioctl(dirfd(d), LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);
1858 if (errno == E2BIG && ret != 0) {
1862 /* if foreign LMV case, fake stripes number */
1863 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
1864 struct lmv_foreign_md *lfm;
1866 lfm = (struct lmv_foreign_md *)param->fp_lmv_md;
1867 if (lfm->lfm_length < XATTR_SIZE_MAX -
1868 offsetof(typeof(*lfm), lfm_value)) {
1869 uint32_t size = lfm->lfm_length +
1870 offsetof(typeof(*lfm), lfm_value);
1872 stripe_count = lmv_foreign_to_md_stripes(size);
1874 llapi_error(LLAPI_MSG_ERROR, -EINVAL,
1875 "error: invalid %d foreign size "
1876 "returned from ioctl",
1881 stripe_count = param->fp_lmv_md->lum_stripe_count;
1883 if (stripe_count <= param->fp_lmv_stripe_count)
1886 free(param->fp_lmv_md);
1887 param->fp_lmv_stripe_count = stripe_count;
1888 lmv_size = lmv_user_md_size(stripe_count,
1889 LMV_USER_MAGIC_SPECIFIC);
1890 param->fp_lmv_md = malloc(lmv_size);
1891 if (param->fp_lmv_md == NULL) {
1892 llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
1893 "error: allocation of %d bytes for ioctl",
1894 lmv_user_md_size(param->fp_lmv_stripe_count,
1895 LMV_USER_MAGIC_SPECIFIC));
1903 static void convert_lmd_statx(struct lov_user_mds_data *lmd_v2, lstat_t *st,
1906 memset(&lmd_v2->lmd_stx, 0, sizeof(lmd_v2->lmd_stx));
1907 lmd_v2->lmd_stx.stx_blksize = st->st_blksize;
1908 lmd_v2->lmd_stx.stx_nlink = st->st_nlink;
1909 lmd_v2->lmd_stx.stx_uid = st->st_uid;
1910 lmd_v2->lmd_stx.stx_gid = st->st_gid;
1911 lmd_v2->lmd_stx.stx_mode = st->st_mode;
1912 lmd_v2->lmd_stx.stx_ino = st->st_ino;
1913 lmd_v2->lmd_stx.stx_size = st->st_size;
1914 lmd_v2->lmd_stx.stx_blocks = st->st_blocks;
1915 lmd_v2->lmd_stx.stx_atime.tv_sec = st->st_atime;
1916 lmd_v2->lmd_stx.stx_ctime.tv_sec = st->st_ctime;
1917 lmd_v2->lmd_stx.stx_mtime.tv_sec = st->st_mtime;
1918 lmd_v2->lmd_stx.stx_rdev_major = major(st->st_rdev);
1919 lmd_v2->lmd_stx.stx_rdev_minor = minor(st->st_rdev);
1920 lmd_v2->lmd_stx.stx_dev_major = major(st->st_dev);
1921 lmd_v2->lmd_stx.stx_dev_minor = minor(st->st_dev);
1922 lmd_v2->lmd_stx.stx_mask |= STATX_BASIC_STATS;
1924 lmd_v2->lmd_flags = 0;
1926 lmd_v2->lmd_flags |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
1928 lmd_v2->lmd_stx.stx_mask &= ~(STATX_SIZE | STATX_BLOCKS);
1929 if (lmd_v2->lmd_stx.stx_size)
1930 lmd_v2->lmd_flags |= OBD_MD_FLLAZYSIZE;
1931 if (lmd_v2->lmd_stx.stx_blocks)
1932 lmd_v2->lmd_flags |= OBD_MD_FLLAZYBLOCKS;
1934 lmd_v2->lmd_flags |= OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1935 OBD_MD_FLBLKSZ | OBD_MD_FLMODE | OBD_MD_FLTYPE |
1936 OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLNLINK |
1941 static int convert_lmdbuf_v1v2(void *lmdbuf, int lmdlen)
1943 struct lov_user_mds_data_v1 *lmd_v1 = lmdbuf;
1944 struct lov_user_mds_data *lmd_v2 = lmdbuf;
1948 size = lov_comp_md_size((struct lov_comp_md_v1 *)&lmd_v1->lmd_lmm);
1952 if (lmdlen < sizeof(lmd_v1->lmd_st) + size)
1955 st = lmd_v1->lmd_st;
1956 memmove(&lmd_v2->lmd_lmm, &lmd_v1->lmd_lmm,
1957 lmdlen - (&lmd_v2->lmd_lmm - &lmd_v1->lmd_lmm));
1958 convert_lmd_statx(lmd_v2, &st, false);
1959 lmd_v2->lmd_lmmsize = 0;
1960 lmd_v2->lmd_padding = 0;
1965 int get_lmd_info_fd(const char *path, int parent_fd, int dir_fd,
1966 void *lmdbuf, int lmdlen, enum get_lmd_info_type type)
1968 struct lov_user_mds_data *lmd = lmdbuf;
1969 static bool use_old_ioctl;
1973 if (parent_fd < 0 && dir_fd < 0)
1975 if (type != GET_LMD_INFO && type != GET_LMD_STRIPE)
1979 /* LL_IOC_MDC_GETINFO operates on the current directory inode
1980 * and returns struct lov_user_mds_data, while
1981 * LL_IOC_LOV_GETSTRIPE returns only struct lov_user_md.
1983 if (type == GET_LMD_INFO)
1984 cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_OLD :
1987 cmd = LL_IOC_LOV_GETSTRIPE;
1990 ret = ioctl(dir_fd, cmd, lmdbuf);
1991 if (ret < 0 && errno == ENOTTY && cmd == LL_IOC_MDC_GETINFO) {
1992 cmd = LL_IOC_MDC_GETINFO_OLD;
1993 use_old_ioctl = true;
1997 if (cmd == LL_IOC_MDC_GETINFO_OLD && !ret)
1998 ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
1999 } else if (parent_fd >= 0) {
2000 const char *fname = strrchr(path, '/');
2002 /* IOC_MDC_GETFILEINFO takes as input the filename (relative to
2003 * the parent directory) and returns struct lov_user_mds_data,
2004 * while IOC_MDC_GETFILESTRIPE returns only struct lov_user_md.
2006 * This avoids opening, locking, and closing each file on the
2007 * client if that is not needed. Multiple of these ioctl() can
2008 * be done on the parent dir with a single open for all
2009 * files in that directory, and it also doesn't pollute the
2010 * client dcache with millions of dentries when traversing
2011 * a large filesystem.
2013 fname = (fname == NULL ? path : fname + 1);
2015 ret = snprintf(lmdbuf, lmdlen, "%s", fname);
2018 else if (ret >= lmdlen || ret++ == 0)
2021 if (type == GET_LMD_INFO)
2022 cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_OLD :
2023 IOC_MDC_GETFILEINFO;
2025 cmd = IOC_MDC_GETFILESTRIPE;
2028 ret = ioctl(parent_fd, cmd, lmdbuf);
2029 if (ret < 0 && errno == ENOTTY &&
2030 cmd == IOC_MDC_GETFILEINFO) {
2031 cmd = IOC_MDC_GETFILEINFO_OLD;
2032 use_old_ioctl = true;
2033 goto retry_getfileinfo;
2036 if (cmd == IOC_MDC_GETFILEINFO_OLD && !ret)
2037 ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
2041 if (ret && type == GET_LMD_INFO) {
2042 if (errno == ENOTTY) {
2045 /* ioctl is not supported, it is not a lustre fs.
2046 * Do the regular lstat(2) instead.
2048 ret = lstat_f(path, &st);
2051 llapi_error(LLAPI_MSG_ERROR, ret,
2052 "error: %s: lstat failed for %s",
2056 convert_lmd_statx(lmd, &st, true);
2057 /* It may be wrong to set use_old_ioctl with true as
2058 * the file is not a lustre fs. So reset it with false
2061 use_old_ioctl = false;
2062 } else if (errno == ENOENT) {
2064 llapi_error(LLAPI_MSG_WARN, ret,
2065 "warning: %s does not exist", path);
2066 } else if (errno != EISDIR && errno != ENODATA) {
2068 llapi_error(LLAPI_MSG_ERROR, ret,
2069 "%s ioctl failed for %s.",
2070 dir_fd >= 0 ? "LL_IOC_MDC_GETINFO" :
2071 "IOC_MDC_GETFILEINFO", path);
2078 static int get_lmd_info(char *path, DIR *parent, DIR *dir, void *lmdbuf,
2079 int lmdlen, enum get_lmd_info_type type)
2085 parent_fd = dirfd(parent);
2087 dir_fd = dirfd(dir);
2089 return get_lmd_info_fd(path, parent_fd, dir_fd, lmdbuf, lmdlen, type);
2092 static int llapi_semantic_traverse(char *path, int size, DIR *parent,
2093 semantic_func_t sem_init,
2094 semantic_func_t sem_fini, void *data,
2095 struct dirent64 *de)
2097 struct find_param *param = (struct find_param *)data;
2098 struct dirent64 *dent;
2106 if (!d && errno != ENOTDIR) {
2108 llapi_error(LLAPI_MSG_ERROR, ret, "%s: Failed to open '%s'",
2111 } else if (!d && !parent) {
2112 /* ENOTDIR. Open the parent dir. */
2113 p = opendir_parent(path);
2120 if (sem_init && (ret = sem_init(path, parent ?: p, &d, data, de)))
2126 while ((dent = readdir64(d)) != NULL) {
2129 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
2133 if ((len + dent->d_reclen + 2) > size) {
2134 llapi_err_noerrno(LLAPI_MSG_ERROR,
2135 "error: %s: string buffer too small",
2140 strcat(path, dent->d_name);
2142 if (dent->d_type == DT_UNKNOWN) {
2143 struct lov_user_mds_data *lmd = param->fp_lmd;
2145 rc = get_lmd_info(path, d, NULL, lmd,
2146 param->fp_lum_size, GET_LMD_INFO);
2148 dent->d_type = IFTODT(lmd->lmd_stx.stx_mode);
2155 switch (dent->d_type) {
2157 llapi_err_noerrno(LLAPI_MSG_ERROR,
2158 "error: %s: '%s' is UNKNOWN type %d",
2159 __func__, dent->d_name, dent->d_type);
2162 rc = llapi_semantic_traverse(path, size, d, sem_init,
2163 sem_fini, data, dent);
2164 if (rc != 0 && ret == 0)
2170 rc = sem_init(path, d, NULL, data, dent);
2171 if (rc < 0 && ret == 0) {
2176 if (sem_fini && rc == 0)
2177 sem_fini(path, d, NULL, data, dent);
2185 sem_fini(path, parent, &d, data, de);
2194 static int param_callback(char *path, semantic_func_t sem_init,
2195 semantic_func_t sem_fini, struct find_param *param)
2197 int ret, len = strlen(path);
2200 if (len > PATH_MAX) {
2202 llapi_error(LLAPI_MSG_ERROR, ret,
2203 "Path name '%s' is too long", path);
2207 buf = (char *)malloc(PATH_MAX + 1);
2211 snprintf(buf, PATH_MAX + 1, "%s", path);
2212 ret = common_param_init(param, buf);
2216 param->fp_depth = 0;
2218 ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, sem_init,
2219 sem_fini, param, NULL);
2221 find_param_fini(param);
2223 return ret < 0 ? ret : 0;
2226 int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_name)
2228 int rc = ioctl(fd, OBD_IOC_GETNAME, lov_name);
2232 llapi_error(LLAPI_MSG_ERROR, rc, "cannot get lov name");
2237 int llapi_file_fget_lmv_uuid(int fd, struct obd_uuid *lov_name)
2239 int rc = ioctl(fd, OBD_IOC_GETMDNAME, lov_name);
2242 llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get lmv name.");
2247 int llapi_file_get_lov_uuid(const char *path, struct obd_uuid *lov_uuid)
2251 fd = open(path, O_RDONLY | O_NONBLOCK);
2254 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", path);
2258 rc = llapi_file_fget_lov_uuid(fd, lov_uuid);
2264 int llapi_file_get_lmv_uuid(const char *path, struct obd_uuid *lov_uuid)
2268 fd = open(path, O_RDONLY | O_NONBLOCK);
2271 llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path);
2275 rc = llapi_file_fget_lmv_uuid(fd, lov_uuid);
2287 * If uuidp is NULL, return the number of available obd uuids.
2288 * If uuidp is non-NULL, then it will return the uuids of the obds. If
2289 * there are more OSTs than allocated to uuidp, then an error is returned with
2290 * the ost_count set to number of available obd uuids.
2292 static int llapi_get_target_uuids(int fd, struct obd_uuid *uuidp,
2293 int *ost_count, enum tgt_type type)
2295 char buf[PATH_MAX], format[32];
2296 int rc = 0, index = 0;
2297 struct obd_uuid name;
2301 /* Get the lov name */
2302 if (type == LOV_TYPE)
2303 rc = llapi_file_fget_lov_uuid(fd, &name);
2305 rc = llapi_file_fget_lmv_uuid(fd, &name);
2309 /* Now get the ost uuids */
2310 rc = get_lustre_param_path(type == LOV_TYPE ? "lov" : "lmv", name.uuid,
2311 FILTER_BY_EXACT, "target_obd", ¶m);
2315 fp = fopen(param.gl_pathv[0], "r");
2318 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
2323 snprintf(format, sizeof(format),
2324 "%%d: %%%zus", sizeof(uuidp[0].uuid) - 1);
2325 while (fgets(buf, sizeof(buf), fp) != NULL) {
2326 if (uuidp && (index < *ost_count)) {
2327 if (sscanf(buf, format, &index, uuidp[index].uuid) < 2)
2335 if (uuidp && (index > *ost_count))
2340 cfs_free_param_data(¶m);
2344 int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count)
2346 return llapi_get_target_uuids(fd, uuidp, ost_count, LOV_TYPE);
2349 int llapi_get_obd_count(char *mnt, int *count, int is_mdt)
2354 root = open(mnt, O_RDONLY | O_DIRECTORY);
2357 llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
2362 rc = ioctl(root, LL_IOC_GETOBDCOUNT, count);
2370 /* Check if user specified value matches a real uuid. Ignore _UUID,
2371 * -osc-4ba41334, other trailing gunk in comparison.
2372 * @param real_uuid ends in "_UUID"
2373 * @param search_uuid may or may not end in "_UUID"
2375 int llapi_uuid_match(char *real_uuid, char *search_uuid)
2377 int cmplen = strlen(real_uuid);
2378 int searchlen = strlen(search_uuid);
2380 if (cmplen > 5 && strcmp(real_uuid + cmplen - 5, "_UUID") == 0)
2382 if (searchlen > 5 && strcmp(search_uuid + searchlen - 5, "_UUID") == 0)
2385 /* The UUIDs may legitimately be different lengths, if
2386 * the system was upgraded from an older version. */
2387 if (cmplen != searchlen)
2390 return (strncmp(search_uuid, real_uuid, cmplen) == 0);
2393 /* Here, param->fp_obd_uuid points to a single obduuid, the index of which is
2394 * returned in param->fp_obd_index */
2395 static int setup_obd_uuid(int fd, char *dname, struct find_param *param)
2397 struct obd_uuid obd_uuid;
2404 if (param->fp_got_uuids)
2407 /* Get the lov/lmv name */
2408 if (param->fp_get_lmv)
2409 rc = llapi_file_fget_lmv_uuid(fd, &obd_uuid);
2411 rc = llapi_file_fget_lov_uuid(fd, &obd_uuid);
2413 if (rc != -ENOTTY) {
2414 llapi_error(LLAPI_MSG_ERROR, rc,
2415 "error: can't get %s name: %s",
2416 param->fp_get_lmv ? "lmv" : "lov",
2424 param->fp_got_uuids = 1;
2426 /* Now get the ost uuids */
2427 rc = get_lustre_param_path(param->fp_get_lmv ? "lmv" : "lov",
2428 obd_uuid.uuid, FILTER_BY_EXACT,
2429 "target_obd", ¶m_data);
2433 fp = fopen(param_data.gl_pathv[0], "r");
2436 llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'",
2437 param_data.gl_pathv[0]);
2441 if (!param->fp_obd_uuid && !param->fp_quiet && !param->fp_obds_printed)
2442 llapi_printf(LLAPI_MSG_NORMAL, "%s:\n",
2443 param->fp_get_lmv ? "MDTS" : "OBDS");
2445 snprintf(format, sizeof(format),
2446 "%%d: %%%zus", sizeof(obd_uuid.uuid) - 1);
2447 while (fgets(buf, sizeof(buf), fp) != NULL) {
2450 if (sscanf(buf, format, &index, obd_uuid.uuid) < 2)
2453 if (param->fp_obd_uuid) {
2454 if (llapi_uuid_match(obd_uuid.uuid,
2455 param->fp_obd_uuid->uuid)) {
2456 param->fp_obd_index = index;
2459 } else if (!param->fp_quiet && !param->fp_obds_printed) {
2460 /* Print everything */
2461 llapi_printf(LLAPI_MSG_NORMAL, "%s", buf);
2464 param->fp_obds_printed = 1;
2468 if (param->fp_obd_uuid && (param->fp_obd_index == OBD_NOT_FOUND)) {
2469 llapi_err_noerrno(LLAPI_MSG_ERROR,
2470 "error: %s: unknown obduuid: %s",
2471 __func__, param->fp_obd_uuid->uuid);
2475 cfs_free_param_data(¶m_data);
2479 /* In this case, param->fp_obd_uuid will be an array of obduuids and
2480 * obd index for all these obduuids will be returned in
2481 * param->fp_obd_indexes */
2482 static int setup_indexes(DIR *dir, char *path, struct obd_uuid *obduuids,
2483 int num_obds, int **obdindexes, int *obdindex,
2486 int ret, obdcount, obd_valid = 0, obdnum;
2488 struct obd_uuid *uuids = NULL;
2492 if (type == LOV_TYPE)
2493 ret = get_param_lov(path, "numobd", buf, sizeof(buf));
2495 ret = get_param_lmv(path, "numobd", buf, sizeof(buf));
2499 obdcount = atoi(buf);
2500 uuids = malloc(obdcount * sizeof(struct obd_uuid));
2505 ret = llapi_get_target_uuids(dirfd(dir), uuids, &obdcount, type);
2507 if (ret == -EOVERFLOW) {
2508 struct obd_uuid *uuids_temp;
2510 uuids_temp = realloc(uuids, obdcount *
2511 sizeof(struct obd_uuid));
2512 if (uuids_temp != NULL) {
2514 goto retry_get_uuids;
2519 llapi_error(LLAPI_MSG_ERROR, ret, "cannot get ost uuid");
2523 indexes = malloc(num_obds * sizeof(*obdindex));
2524 if (indexes == NULL) {
2529 for (obdnum = 0; obdnum < num_obds; obdnum++) {
2532 /* The user may have specified a simple index */
2533 i = strtol(obduuids[obdnum].uuid, &end, 0);
2534 if (end && *end == '\0' && i < obdcount) {
2535 indexes[obdnum] = i;
2538 for (i = 0; i < obdcount; i++) {
2539 if (llapi_uuid_match(uuids[i].uuid,
2540 obduuids[obdnum].uuid)) {
2541 indexes[obdnum] = i;
2547 if (i >= obdcount) {
2548 indexes[obdnum] = OBD_NOT_FOUND;
2549 llapi_err_noerrno(LLAPI_MSG_ERROR,
2550 "invalid obduuid '%s'",
2551 obduuids[obdnum].uuid);
2557 *obdindex = OBD_NOT_FOUND;
2559 *obdindex = obd_valid;
2561 *obdindexes = indexes;
2569 static int setup_target_indexes(DIR *dir, char *path, struct find_param *param)
2573 if (param->fp_mdt_uuid) {
2574 ret = setup_indexes(dir, path, param->fp_mdt_uuid,
2576 ¶m->fp_mdt_indexes,
2577 ¶m->fp_mdt_index, LMV_TYPE);
2582 if (param->fp_obd_uuid) {
2583 ret = setup_indexes(dir, path, param->fp_obd_uuid,
2585 ¶m->fp_obd_indexes,
2586 ¶m->fp_obd_index, LOV_TYPE);
2591 param->fp_got_uuids = 1;
2596 int llapi_ostlist(char *path, struct find_param *param)
2601 fd = open(path, O_RDONLY | O_DIRECTORY);
2605 ret = setup_obd_uuid(fd, path, param);
2612 * Tries to determine the default stripe attributes for a given filesystem. The
2613 * filesystem to check should be specified by fsname, or will be determined
2616 static int sattr_get_defaults(const char *const fsname,
2617 unsigned int *scount,
2618 unsigned int *ssize,
2619 unsigned int *soffset)
2625 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2626 "stripecount", val, sizeof(val));
2629 *scount = atoi(val);
2633 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2634 "stripesize", val, sizeof(val));
2641 rc = get_lustre_param_value("lov", fsname, FILTER_BY_FS_NAME,
2642 "stripeoffset", val, sizeof(val));
2645 *soffset = atoi(val);
2652 * Tries to gather the default stripe attributes for a given filesystem. If
2653 * the attributes can be determined, they are cached for easy retreival the
2654 * next time they are needed. Only a single filesystem's attributes are
2657 int sattr_cache_get_defaults(const char *const fsname,
2658 const char *const pathname, unsigned int *scount,
2659 unsigned int *ssize, unsigned int *soffset)
2662 char fsname[PATH_MAX + 1];
2663 unsigned int stripecount;
2664 unsigned int stripesize;
2665 unsigned int stripeoffset;
2671 char fsname_buf[PATH_MAX + 1];
2672 unsigned int tmp[3];
2674 if (fsname == NULL) {
2675 rc = llapi_search_fsname(pathname, fsname_buf);
2679 snprintf(fsname_buf, sizeof(fsname_buf), "%s", fsname);
2682 if (strncmp(fsname_buf, cache.fsname, sizeof(fsname_buf) - 1) != 0) {
2684 * Ensure all 3 sattrs (count, size, and offset) are
2685 * successfully retrieved and stored in tmp before writing to
2688 rc = sattr_get_defaults(fsname_buf, &tmp[0], &tmp[1], &tmp[2]);
2692 cache.stripecount = tmp[0];
2693 cache.stripesize = tmp[1];
2694 cache.stripeoffset = tmp[2];
2695 snprintf(cache.fsname, sizeof(cache.fsname), "%s", fsname_buf);
2699 *scount = cache.stripecount;
2701 *ssize = cache.stripesize;
2703 *soffset = cache.stripeoffset;
2708 static char *layout2name(__u32 layout_pattern)
2710 if (layout_pattern & LOV_PATTERN_F_RELEASED)
2712 else if (layout_pattern == LOV_PATTERN_MDT)
2714 else if (layout_pattern == LOV_PATTERN_RAID0)
2716 else if (layout_pattern ==
2717 (LOV_PATTERN_RAID0 | LOV_PATTERN_OVERSTRIPING))
2718 return "raid0,overstriped";
2723 enum lov_dump_flags {
2724 LDF_IS_DIR = 0x0001,
2725 LDF_IS_RAW = 0x0002,
2726 LDF_INDENT = 0x0004,
2727 LDF_SKIP_OBJS = 0x0008,
2729 LDF_EXTENSION = 0x0020,
2732 static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
2733 struct lov_user_ost_data_v1 *objects,
2734 enum llapi_layout_verbose verbose,
2735 int depth, char *pool_name,
2736 enum lov_dump_flags flags)
2738 bool is_dir = flags & LDF_IS_DIR;
2739 bool is_raw = flags & LDF_IS_RAW;
2740 bool indent = flags & LDF_INDENT;
2741 bool yaml = flags & LDF_YAML;
2742 bool skip_objs = flags & LDF_SKIP_OBJS;
2743 bool extension = flags & LDF_EXTENSION;
2744 char *prefix = is_dir ? "" : "lmm_";
2745 char *separator = "";
2746 char *space = indent ? " " : "";
2749 if (is_dir && lmm_oi_seq(&lum->lmm_oi) == FID_SEQ_LOV_DEFAULT) {
2750 lmm_oi_set_seq(&lum->lmm_oi, 0);
2751 if (!indent && (verbose & VERBOSE_DETAIL))
2752 llapi_printf(LLAPI_MSG_NORMAL, "%s(Default) ", space);
2755 if (!yaml && !indent && depth && path &&
2756 ((verbose != VERBOSE_OBJID) || !is_dir))
2757 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
2759 if ((verbose & VERBOSE_DETAIL) && !is_dir) {
2760 llapi_printf(LLAPI_MSG_NORMAL, "%s%smagic: 0x%08X\n",
2761 space, prefix, lum->lmm_magic);
2762 llapi_printf(LLAPI_MSG_NORMAL, "%s%sseq: %#jx\n",
2764 (uintmax_t)lmm_oi_seq(&lum->lmm_oi));
2765 llapi_printf(LLAPI_MSG_NORMAL, "%s%sobject_id: %#jx\n",
2767 (uintmax_t)lmm_oi_id(&lum->lmm_oi));
2769 if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) {
2774 if (verbose & ~VERBOSE_DFID)
2775 llapi_printf(LLAPI_MSG_NORMAL, "%slmm_fid: ",
2777 /* This needs a bit of hand-holding since old 1.x lmm_oi
2778 * have { oi.oi_id = mds_inum, oi.oi_seq = 0 } and 2.x lmm_oi
2779 * have { oi.oi_id = mds_oid, oi.oi_seq = mds_seq } instead of
2780 * a real FID. Ideally the 2.x code would have stored this
2781 * like a FID with { oi_id = mds_seq, oi_seq = mds_oid } so the
2782 * ostid union lu_fid { f_seq = mds_seq, f_oid = mds_oid }
2783 * worked properly (especially since IGIF FIDs use mds_inum as
2784 * the FID SEQ), but unfortunately that didn't happen.
2786 * Print it to look like an IGIF FID, even though the fields
2787 * are reversed on disk, so that it makes sense to userspace.
2789 * Don't use ostid_id() and ostid_seq(), since they assume the
2790 * oi_fid fields are in the right order. This is why there are
2791 * separate lmm_oi_seq() and lmm_oi_id() routines for this.
2793 * For newer layout types hopefully this will be a real FID. */
2794 seq = lmm_oi_seq(&lum->lmm_oi) == 0 ?
2795 lmm_oi_id(&lum->lmm_oi) : lmm_oi_seq(&lum->lmm_oi);
2796 oid = lmm_oi_seq(&lum->lmm_oi) == 0 ?
2797 0 : (__u32)lmm_oi_id(&lum->lmm_oi);
2798 ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32);
2800 llapi_printf(LLAPI_MSG_NORMAL, DFID_NOBRACE"\n",
2801 (unsigned long long)seq, oid, ver);
2803 llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
2804 (unsigned long long)seq, oid, ver);
2807 if (verbose & VERBOSE_STRIPE_COUNT) {
2808 if (verbose & ~VERBOSE_STRIPE_COUNT)
2809 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_count: ",
2812 if (!is_raw && lum->lmm_stripe_count == 0 &&
2813 lov_pattern(lum->lmm_pattern) != LOV_PATTERN_MDT) {
2814 unsigned int scount;
2815 rc = sattr_cache_get_defaults(NULL, path,
2819 llapi_printf(LLAPI_MSG_NORMAL, "%d",
2822 llapi_error(LLAPI_MSG_ERROR, rc,
2823 "Cannot determine default"
2826 llapi_printf(LLAPI_MSG_NORMAL, "%d",
2828 (__s16)lum->lmm_stripe_count);
2831 llapi_printf(LLAPI_MSG_NORMAL, "%hd",
2833 (__s16)lum->lmm_stripe_count);
2835 if (!yaml && is_dir)
2841 if (((verbose & VERBOSE_STRIPE_SIZE) && !extension) ||
2842 ((verbose & VERBOSE_EXT_SIZE) && extension)) {
2843 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
2844 if (verbose & ~VERBOSE_EXT_SIZE && extension)
2845 llapi_printf(LLAPI_MSG_NORMAL, "%s%sextension_size: ",
2847 if (verbose & ~VERBOSE_STRIPE_SIZE && !extension)
2848 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_size: ",
2850 if (is_dir && !is_raw && lum->lmm_stripe_size == 0) {
2852 rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
2855 llapi_printf(LLAPI_MSG_NORMAL, "%u", ssize);
2857 llapi_error(LLAPI_MSG_ERROR, rc,
2858 "Cannot determine default"
2861 /* Extension size is in KiB */
2862 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
2864 (unsigned long long)(lum->lmm_stripe_size * SEL_UNIT_SIZE) :
2865 (unsigned long long)lum->lmm_stripe_size);
2867 if (!yaml && is_dir)
2873 if ((verbose & VERBOSE_PATTERN)) {
2874 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
2875 if (verbose & ~VERBOSE_PATTERN)
2876 llapi_printf(LLAPI_MSG_NORMAL, "%s%spattern: ",
2878 if (lov_pattern_supported(lum->lmm_pattern))
2879 llapi_printf(LLAPI_MSG_NORMAL, "%s",
2880 layout2name(lum->lmm_pattern));
2882 llapi_printf(LLAPI_MSG_NORMAL, "%x", lum->lmm_pattern);
2883 separator = (!yaml && is_dir) ? " " : "\n";
2886 if ((verbose & VERBOSE_GENERATION) && !is_dir) {
2887 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
2888 if (verbose & ~VERBOSE_GENERATION)
2889 llapi_printf(LLAPI_MSG_NORMAL, "%s%slayout_gen: ",
2891 llapi_printf(LLAPI_MSG_NORMAL, "%u",
2892 skip_objs ? 0 : (int)lum->lmm_layout_gen);
2896 if (verbose & VERBOSE_STRIPE_OFFSET) {
2897 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
2898 if (verbose & ~VERBOSE_STRIPE_OFFSET)
2899 llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_offset: ",
2901 if (is_dir || skip_objs)
2902 llapi_printf(LLAPI_MSG_NORMAL, "%d",
2903 lum->lmm_stripe_offset ==
2904 (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
2905 lum->lmm_stripe_offset);
2906 else if (lov_pattern(lum->lmm_pattern) == LOV_PATTERN_MDT)
2907 llapi_printf(LLAPI_MSG_NORMAL, "0");
2909 llapi_printf(LLAPI_MSG_NORMAL, "%u",
2910 objects[0].l_ost_idx);
2911 if (!yaml && is_dir)
2917 if ((verbose & VERBOSE_POOL) && pool_name && (pool_name[0] != '\0')) {
2918 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
2919 if (verbose & ~VERBOSE_POOL)
2920 llapi_printf(LLAPI_MSG_NORMAL, "%s%spool: ",
2922 llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name);
2923 if (!yaml && is_dir)
2929 if (strlen(separator) != 0)
2930 llapi_printf(LLAPI_MSG_NORMAL, "\n");
2933 void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
2934 struct lov_user_ost_data_v1 *objects,
2935 char *path, int obdindex, int depth,
2936 enum llapi_layout_verbose verbose,
2937 enum lov_dump_flags flags)
2939 bool is_dir = flags & LDF_IS_DIR;
2940 bool indent = flags & LDF_INDENT;
2941 bool skip_objs = flags & LDF_SKIP_OBJS;
2942 bool yaml = flags & LDF_YAML;
2943 bool obdstripe = obdindex == OBD_NOT_FOUND;
2946 if (!obdstripe && !skip_objs) {
2947 for (i = 0; !is_dir && i < lum->lmm_stripe_count; i++) {
2948 if (obdindex == objects[i].l_ost_idx) {
2958 lov_dump_user_lmm_header(lum, path, objects, verbose, depth, pool_name,
2961 if (!is_dir && !skip_objs && (verbose & VERBOSE_OBJID) &&
2962 !(lum->lmm_pattern & LOV_PATTERN_F_RELEASED ||
2963 lov_pattern(lum->lmm_pattern) == LOV_PATTERN_MDT)) {
2964 char *space = " - ";
2967 llapi_printf(LLAPI_MSG_NORMAL,
2968 "%6slmm_objects:\n", " ");
2970 llapi_printf(LLAPI_MSG_NORMAL, "lmm_objects:\n");
2972 llapi_printf(LLAPI_MSG_NORMAL,
2973 "\tobdidx\t\t objid\t\t objid\t\t group\n");
2975 for (i = 0; i < lum->lmm_stripe_count; i++) {
2976 int idx = objects[i].l_ost_idx;
2977 long long oid = ostid_id(&objects[i].l_ost_oi);
2978 long long gr = ostid_seq(&objects[i].l_ost_oi);
2980 if (obdindex != OBD_NOT_FOUND && obdindex != idx)
2984 struct lu_fid fid = { 0 };
2986 ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
2987 llapi_printf(LLAPI_MSG_NORMAL,
2988 "%sl_ost_idx: %d\n", space, idx);
2989 llapi_printf(LLAPI_MSG_NORMAL,
2990 "%8sl_fid: "DFID_NOBRACE"\n",
2992 } else if (indent) {
2993 struct lu_fid fid = { 0 };
2995 ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
2996 llapi_printf(LLAPI_MSG_NORMAL,
2997 "%s%d: { l_ost_idx: %d, l_fid: "DFID" }\n",
2998 space, i, idx, PFID(&fid));
3001 sprintf(fmt, "%s%s%s\n",
3002 "\t%6u\t%14llu\t%#13llx\t",
3003 (fid_seq_is_rsvd(gr) ||
3004 fid_seq_is_mdt0(gr)) ?
3005 "%14llu" : "%#14llx", "%s");
3006 llapi_printf(LLAPI_MSG_NORMAL, fmt, idx, oid,
3008 obdindex == idx ? " *" : "");
3012 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3015 void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name,
3016 char *path, int obdindex, int depth,
3017 enum llapi_layout_verbose verbose,
3018 enum lov_dump_flags flags)
3020 struct lmv_user_mds_data *objects = lum->lum_objects;
3021 char *prefix = lum->lum_magic == LMV_USER_MAGIC ? "(Default)" : "";
3022 char *separator = "";
3023 bool yaml = flags & LDF_YAML;
3024 bool obdstripe = false;
3027 if (obdindex != OBD_NOT_FOUND) {
3028 if (lum->lum_stripe_count == 0) {
3029 if (obdindex == lum->lum_stripe_offset)
3032 for (i = 0; i < lum->lum_stripe_count; i++) {
3033 if (obdindex == objects[i].lum_mds) {
3034 llapi_printf(LLAPI_MSG_NORMAL,
3049 /* show all information default */
3051 if (lum->lum_magic == LMV_USER_MAGIC)
3052 verbose = VERBOSE_POOL | VERBOSE_STRIPE_COUNT |
3053 VERBOSE_STRIPE_OFFSET | VERBOSE_HASH_TYPE;
3055 verbose = VERBOSE_OBJID;
3058 if (depth && path && ((verbose != VERBOSE_OBJID)))
3059 llapi_printf(LLAPI_MSG_NORMAL, "%s%s\n", prefix, path);
3061 if (verbose & VERBOSE_STRIPE_COUNT) {
3062 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3063 if (verbose & ~VERBOSE_STRIPE_COUNT)
3064 llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_count: ");
3065 llapi_printf(LLAPI_MSG_NORMAL, "%u",
3066 (int)lum->lum_stripe_count);
3067 if ((verbose & VERBOSE_STRIPE_OFFSET) && !yaml)
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, "lmv_stripe_offset: ");
3077 llapi_printf(LLAPI_MSG_NORMAL, "%d",
3078 (int)lum->lum_stripe_offset);
3079 if (verbose & VERBOSE_HASH_TYPE && !yaml)
3085 if (verbose & VERBOSE_HASH_TYPE) {
3086 unsigned int type = lum->lum_hash_type & LMV_HASH_TYPE_MASK;
3087 unsigned int flags = lum->lum_hash_type & ~LMV_HASH_TYPE_MASK;
3089 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3090 if (verbose & ~VERBOSE_HASH_TYPE)
3091 llapi_printf(LLAPI_MSG_NORMAL, "lmv_hash_type: ");
3092 if (type < LMV_HASH_TYPE_MAX)
3093 llapi_printf(LLAPI_MSG_NORMAL, "%s",
3094 mdt_hash_name[type]);
3096 llapi_printf(LLAPI_MSG_NORMAL, "%#x", type);
3098 if (flags & LMV_HASH_FLAG_MIGRATION)
3099 llapi_printf(LLAPI_MSG_NORMAL, ",migrating");
3100 if (flags & LMV_HASH_FLAG_BAD_TYPE)
3101 llapi_printf(LLAPI_MSG_NORMAL, ",bad_type");
3102 if (flags & LMV_HASH_FLAG_LOST_LMV)
3103 llapi_printf(LLAPI_MSG_NORMAL, ",lost_lmv");
3108 if (verbose & VERBOSE_OBJID && lum->lum_magic != LMV_USER_MAGIC) {
3109 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3110 if (lum->lum_stripe_count > 0)
3111 llapi_printf(LLAPI_MSG_NORMAL,
3112 "mdtidx\t\t FID[seq:oid:ver]\n");
3113 for (i = 0; i < lum->lum_stripe_count; i++) {
3114 int idx = objects[i].lum_mds;
3115 struct lu_fid *fid = &objects[i].lum_fid;
3116 if ((obdindex == OBD_NOT_FOUND) || (obdindex == idx))
3117 llapi_printf(LLAPI_MSG_NORMAL,
3118 "%6u\t\t "DFID"\t\t%s\n",
3120 obdindex == idx ? " *" : "");
3125 if ((verbose & VERBOSE_POOL) && pool_name != NULL &&
3126 pool_name[0] != '\0') {
3127 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3128 if (verbose & ~VERBOSE_POOL)
3129 llapi_printf(LLAPI_MSG_NORMAL, "%slmv_pool: ",
3131 llapi_printf(LLAPI_MSG_NORMAL, "%s%c ", pool_name, ' ');
3135 if (!(verbose & VERBOSE_OBJID) || lum->lum_magic == LMV_USER_MAGIC)
3136 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3139 static void lov_dump_comp_v1_header(struct find_param *param, char *path,
3140 enum lov_dump_flags flags)
3142 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3143 int depth = param->fp_max_depth;
3144 enum llapi_layout_verbose verbose = param->fp_verbose;
3145 bool yaml = flags & LDF_YAML;
3147 if (depth && path && ((verbose != VERBOSE_OBJID) ||
3148 !(flags & LDF_IS_DIR)) && !yaml)
3149 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
3151 if (verbose & VERBOSE_DETAIL) {
3152 llapi_printf(LLAPI_MSG_NORMAL, "composite_header:\n");
3153 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_magic: 0x%08X\n",
3154 " ", comp_v1->lcm_magic);
3155 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_size: %u\n",
3156 " ", comp_v1->lcm_size);
3157 if (flags & LDF_IS_DIR)
3158 llapi_printf(LLAPI_MSG_NORMAL,
3159 "%2slcm_flags: %s\n", " ",
3160 comp_v1->lcm_mirror_count > 0 ?
3163 llapi_printf(LLAPI_MSG_NORMAL,
3164 "%2slcm_flags: %s\n", " ",
3165 llapi_layout_flags_string(comp_v1->lcm_flags));
3168 if (verbose & VERBOSE_GENERATION) {
3169 if (verbose & ~VERBOSE_GENERATION)
3170 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_layout_gen: ",
3172 llapi_printf(LLAPI_MSG_NORMAL, "%u\n", comp_v1->lcm_layout_gen);
3175 if (verbose & VERBOSE_MIRROR_COUNT) {
3176 if (verbose & ~VERBOSE_MIRROR_COUNT)
3177 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_mirror_count: ",
3179 llapi_printf(LLAPI_MSG_NORMAL, "%u\n",
3180 comp_v1->lcm_magic == LOV_USER_MAGIC_COMP_V1 ?
3181 comp_v1->lcm_mirror_count + 1 : 1);
3184 if (verbose & VERBOSE_COMP_COUNT) {
3185 if (verbose & ~VERBOSE_COMP_COUNT)
3186 llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_entry_count: ",
3188 llapi_printf(LLAPI_MSG_NORMAL, "%u\n",
3189 comp_v1->lcm_magic == LOV_USER_MAGIC_COMP_V1 ?
3190 comp_v1->lcm_entry_count : 0);
3193 if (verbose & VERBOSE_DETAIL && !yaml)
3194 llapi_printf(LLAPI_MSG_NORMAL, "components:\n");
3197 static void lcme_flags2str(__u32 comp_flags)
3203 llapi_printf(LLAPI_MSG_NORMAL, "0");
3206 for (i = 0; i < ARRAY_SIZE(comp_flags_table); i++) {
3207 if (comp_flags & comp_flags_table[i].cfn_flag) {
3209 llapi_printf(LLAPI_MSG_NORMAL, ",");
3210 llapi_printf(LLAPI_MSG_NORMAL, "%s",
3211 comp_flags_table[i].cfn_name);
3212 comp_flags &= ~comp_flags_table[i].cfn_flag;
3218 llapi_printf(LLAPI_MSG_NORMAL, ",");
3219 llapi_printf(LLAPI_MSG_NORMAL, "%#x", comp_flags);
3223 static void lov_dump_comp_v1_entry(struct find_param *param,
3224 enum lov_dump_flags flags, int index)
3226 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3227 struct lov_comp_md_entry_v1 *entry;
3228 char *separator = "";
3229 enum llapi_layout_verbose verbose = param->fp_verbose;
3230 bool yaml = flags & LDF_YAML;
3232 entry = &comp_v1->lcm_entries[index];
3235 llapi_printf(LLAPI_MSG_NORMAL, "%2scomponent%d:\n", " ", index);
3237 if (verbose & VERBOSE_COMP_ID) {
3238 if (verbose & VERBOSE_DETAIL && !yaml)
3239 llapi_printf(LLAPI_MSG_NORMAL,
3240 "%slcme_id: ", " - ");
3241 else if (verbose & ~VERBOSE_COMP_ID)
3242 llapi_printf(LLAPI_MSG_NORMAL,
3243 "%4slcme_id: ", " ");
3244 if (entry->lcme_id != LCME_ID_INVAL)
3245 llapi_printf(LLAPI_MSG_NORMAL, "%u", entry->lcme_id);
3247 llapi_printf(LLAPI_MSG_NORMAL, "N/A");
3251 if (verbose & VERBOSE_MIRROR_ID) {
3252 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3253 if (verbose & ~VERBOSE_MIRROR_ID)
3254 llapi_printf(LLAPI_MSG_NORMAL,
3255 "%4slcme_mirror_id: ", " ");
3256 if (entry->lcme_id != LCME_ID_INVAL)
3257 llapi_printf(LLAPI_MSG_NORMAL, "%u",
3258 mirror_id_of(entry->lcme_id));
3260 llapi_printf(LLAPI_MSG_NORMAL, "N/A");
3264 if (verbose & VERBOSE_COMP_FLAGS) {
3265 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3266 if (verbose & ~VERBOSE_COMP_FLAGS)
3267 llapi_printf(LLAPI_MSG_NORMAL,
3268 "%4slcme_flags: ", " ");
3269 lcme_flags2str(entry->lcme_flags);
3272 /* print snapshot timestamp if its a nosync comp */
3273 if ((verbose & VERBOSE_COMP_FLAGS) &&
3274 (entry->lcme_flags & LCME_FL_NOSYNC)) {
3275 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3276 if (verbose & ~VERBOSE_COMP_FLAGS)
3277 llapi_printf(LLAPI_MSG_NORMAL,
3278 "%4slcme_timestamp: ", " ");
3280 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3281 (unsigned long long)entry->lcme_timestamp);
3283 time_t stamp = entry->lcme_timestamp;
3284 char *date_str = asctime(localtime(&stamp));
3286 date_str[strlen(date_str) - 1] = '\0';
3287 llapi_printf(LLAPI_MSG_NORMAL, "'%s'", date_str);
3293 if (verbose & VERBOSE_COMP_START) {
3294 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3295 if (verbose & ~VERBOSE_COMP_START)
3296 llapi_printf(LLAPI_MSG_NORMAL,
3297 "%4slcme_extent.e_start: ", " ");
3298 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3299 (unsigned long long)entry->lcme_extent.e_start);
3303 if (verbose & VERBOSE_COMP_END) {
3304 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3305 if (verbose & ~VERBOSE_COMP_END)
3306 llapi_printf(LLAPI_MSG_NORMAL,
3307 "%4slcme_extent.e_end: ", " ");
3308 if (entry->lcme_extent.e_end == LUSTRE_EOF)
3309 llapi_printf(LLAPI_MSG_NORMAL, "%s", "EOF");
3311 llapi_printf(LLAPI_MSG_NORMAL, "%llu",
3312 (unsigned long long)entry->lcme_extent.e_end);
3317 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3318 llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " ");
3319 } else if (verbose & VERBOSE_DETAIL) {
3320 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3321 llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_offset: %u\n",
3322 " ", entry->lcme_offset);
3323 llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_size: %u\n",
3324 " ", entry->lcme_size);
3325 llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " ");
3327 llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
3331 /* Check if the value matches 1 of the given criteria (e.g. --atime +/-N).
3332 * @mds indicates if this is MDS timestamps and there are attributes on OSTs.
3334 * The result is -1 if it does not match, 0 if not yet clear, 1 if matches.
3335 * The table below gives the answers for the specified parameters (value and
3336 * sign), 1st column is the answer for the MDS value, the 2nd is for the OST:
3337 * --------------------------------------
3338 * 1 | file > limit; sign > 0 | -1 / -1 |
3339 * 2 | file = limit; sign > 0 | -1 / -1 |
3340 * 3 | file < limit; sign > 0 | ? / 1 |
3341 * 4 | file > limit; sign = 0 | -1 / -1 |
3342 * 5 | file = limit; sign = 0 | ? / 1 | <- (see the Note below)
3343 * 6 | file < limit; sign = 0 | ? / -1 |
3344 * 7 | file > limit; sign < 0 | 1 / 1 |
3345 * 8 | file = limit; sign < 0 | ? / -1 |
3346 * 9 | file < limit; sign < 0 | ? / -1 |
3347 * --------------------------------------
3348 * Note: 5th actually means that the value is within the interval
3349 * (limit - margin, limit]. */
3350 static int find_value_cmp(unsigned long long file, unsigned long long limit,
3351 int sign, int negopt, unsigned long long margin,
3357 /* Drop the fraction of margin (of days or size). */
3358 if (file + margin <= limit)
3360 } else if (sign == 0) {
3361 if (file <= limit && file + margin > limit)
3363 else if (file + margin <= limit)
3365 } else if (sign < 0) {
3372 return negopt ? ~ret + 1 : ret;
3375 static inline struct lov_user_md *
3376 lov_comp_entry(struct lov_comp_md_v1 *comp_v1, int ent_idx)
3378 return (struct lov_user_md *)((char *)comp_v1 +
3379 comp_v1->lcm_entries[ent_idx].lcme_offset);
3382 static inline struct lov_user_ost_data_v1 *
3383 lov_v1v3_objects(struct lov_user_md *v1)
3385 if (v1->lmm_magic == LOV_USER_MAGIC_V3)
3386 return ((struct lov_user_md_v3 *)v1)->lmm_objects;
3388 return v1->lmm_objects;
3392 lov_v1v3_pool_name(struct lov_user_md *v1, char *pool_name)
3394 if (v1->lmm_magic == LOV_USER_MAGIC_V3)
3395 snprintf(pool_name, LOV_MAXPOOLNAME, "%s",
3396 ((struct lov_user_md_v3 *)v1)->lmm_pool_name);
3398 pool_name[0] = '\0';
3402 print_last_init_comp(struct find_param *param)
3404 /* print all component info */
3405 if ((param->fp_verbose & VERBOSE_DEFAULT) == VERBOSE_DEFAULT)
3408 /* print specific component info */
3409 if (param->fp_check_comp_id || param->fp_check_comp_flags ||
3410 param->fp_check_comp_start || param->fp_check_comp_end ||
3411 param->fp_check_mirror_id || param->fp_check_mirror_index)
3417 static int find_comp_end_cmp(unsigned long long end, struct find_param *param)
3421 if (param->fp_comp_end == LUSTRE_EOF) {
3422 if (param->fp_comp_end_sign == 0) /* equal to EOF */
3423 match = end == LUSTRE_EOF ? 1 : -1;
3424 else if (param->fp_comp_end_sign > 0) /* at most EOF */
3425 match = end == LUSTRE_EOF ? -1 : 1;
3426 else /* at least EOF */
3428 if (param->fp_exclude_comp_end)
3431 unsigned long long margin;
3433 margin = end == LUSTRE_EOF ? 0 : param->fp_comp_end_units;
3434 match = find_value_cmp(end, param->fp_comp_end,
3435 param->fp_comp_end_sign,
3436 param->fp_exclude_comp_end, margin, 0);
3443 * An example of "getstripe -v" for a two components PFL file:
3446 * lcm_magic: 0x0BD60BD0
3450 * lcm_entry_count: 2
3454 * lcme_extent.e_start: 0
3455 * lcme_extent.e_end: 1048576
3459 * lmm_magic: 0x0BD10BD0
3460 * lmm_seq: 0x200000401
3461 * lmm_object_id: 0x1
3462 * lmm_fid: [0x200000401:0x1:0x0]
3463 * lmm_stripe_count: 1
3464 * lmm_stripe_size: 1048576
3465 * lmm_pattern: raid0
3467 * lmm_stripe_offset: 0
3469 * - 0: { l_ost_idx: 0, l_fid: [0x100000000:0x2:0x0] }
3473 * lcme_extent.e_start: 1048576
3474 * lcme_extent.e_end: EOF
3478 * lmm_magic: 0x0BD10BD0
3479 * lmm_seq: 0x200000401
3480 * lmm_object_id: 0x1
3481 * lmm_fid: [0x200000401:0x1:0x0]
3482 * lmm_stripe_count: 2
3483 * lmm_stripe_size: 1048576
3484 * lmm_pattern: raid0
3486 * lmm_stripe_offset: 1
3488 * - 0: { l_ost_idx: 1, l_fid: [0x100010000:0x2:0x0] }
3489 * - 1: { l_ost_idx: 0, l_fid: [0x100000000:0x3:0x0] }
3491 static void lov_dump_comp_v1(struct find_param *param, char *path,
3492 enum lov_dump_flags flags)
3494 struct lov_comp_md_entry_v1 *entry;
3495 struct lov_user_ost_data_v1 *objects;
3496 struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
3497 struct lov_user_md_v1 *v1;
3498 char pool_name[LOV_MAXPOOLNAME + 1];
3499 int obdindex = param->fp_obd_index;
3500 int i, j, match, ext;
3501 bool obdstripe = false;
3502 __u16 mirror_index = 0;
3503 __u16 mirror_id = 0;
3505 if (obdindex != OBD_NOT_FOUND) {
3506 for (i = 0; !(flags & LDF_IS_DIR) && !obdstripe &&
3507 i < comp_v1->lcm_entry_count; i++) {
3508 if (!(comp_v1->lcm_entries[i].lcme_flags &
3512 v1 = lov_comp_entry(comp_v1, i);
3513 objects = lov_v1v3_objects(v1);
3515 for (j = 0; j < v1->lmm_stripe_count; j++) {
3516 if (obdindex == objects[j].l_ost_idx) {
3529 lov_dump_comp_v1_header(param, path, flags);
3531 flags |= LDF_INDENT;
3533 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
3534 entry = &comp_v1->lcm_entries[i];
3536 if (param->fp_check_comp_flags) {
3537 if (((param->fp_comp_flags & entry->lcme_flags) !=
3538 param->fp_comp_flags) ||
3539 (param->fp_comp_neg_flags & entry->lcme_flags))
3543 if (param->fp_check_comp_id &&
3544 param->fp_comp_id != entry->lcme_id)
3547 if (param->fp_check_comp_start) {
3548 match = find_value_cmp(entry->lcme_extent.e_start,
3549 param->fp_comp_start,
3550 param->fp_comp_start_sign,
3552 param->fp_comp_start_units, 0);
3557 if (param->fp_check_comp_end) {
3558 match = find_comp_end_cmp(entry->lcme_extent.e_end,
3564 if (param->fp_check_mirror_index) {
3565 if (mirror_id != mirror_id_of(entry->lcme_id)) {
3567 mirror_id = mirror_id_of(entry->lcme_id);
3570 match = find_value_cmp(mirror_index,
3571 param->fp_mirror_index,
3572 param->fp_mirror_index_sign,
3573 param->fp_exclude_mirror_index,
3577 } else if (param->fp_check_mirror_id) {
3578 if (mirror_id != mirror_id_of(entry->lcme_id))
3579 mirror_id = mirror_id_of(entry->lcme_id);
3581 match = find_value_cmp(mirror_id,
3582 param->fp_mirror_id,
3583 param->fp_mirror_id_sign,
3584 param->fp_exclude_mirror_id,
3590 if (print_last_init_comp(param)) {
3592 * if part of stripe info is needed, we'd print only
3593 * the last instantiated component info.
3595 if (entry->lcme_flags & LCME_FL_INIT)
3598 if (param->fp_verbose & VERBOSE_EXT_SIZE) {
3599 if (entry->lcme_flags & LCME_FL_EXTENSION)
3600 /* moved back below */
3608 if (entry->lcme_flags & LCME_FL_INIT) {
3609 if (obdindex != OBD_NOT_FOUND) {
3610 flags |= LDF_SKIP_OBJS;
3611 v1 = lov_comp_entry(comp_v1, i);
3612 objects = lov_v1v3_objects(v1);
3614 for (j = 0; j < v1->lmm_stripe_count; j++) {
3615 if (obdindex == objects[j].l_ost_idx) {
3616 flags &= ~LDF_SKIP_OBJS;
3621 flags &= ~LDF_SKIP_OBJS;
3624 flags |= LDF_SKIP_OBJS;
3627 if (obdindex != OBD_NOT_FOUND && (flags & LDF_SKIP_OBJS))
3629 lov_dump_comp_v1_entry(param, flags, i);
3631 v1 = lov_comp_entry(comp_v1, i);
3632 objects = lov_v1v3_objects(v1);
3633 lov_v1v3_pool_name(v1, pool_name);
3635 ext = entry->lcme_flags & LCME_FL_EXTENSION ? LDF_EXTENSION : 0;
3636 lov_dump_user_lmm_v1v3(v1, pool_name, objects, path, obdindex,
3637 param->fp_max_depth, param->fp_verbose,
3640 if (print_last_init_comp(param)) {
3642 * directory layout contains only layout template, print the
3646 i = comp_v1->lcm_entry_count - 1;
3649 flags &= ~LDF_SKIP_OBJS;
3651 lov_dump_comp_v1_entry(param, flags, i);
3653 v1 = lov_comp_entry(comp_v1, i);
3654 objects = lov_v1v3_objects(v1);
3655 lov_v1v3_pool_name(v1, pool_name);
3657 entry = &comp_v1->lcm_entries[i];
3658 ext = entry->lcme_flags & LCME_FL_EXTENSION ? LDF_EXTENSION : 0;
3659 lov_dump_user_lmm_v1v3(v1, pool_name, objects, path, obdindex,
3660 param->fp_max_depth, param->fp_verbose,
3665 #define VERBOSE_COMP_OPTS (VERBOSE_COMP_COUNT | VERBOSE_COMP_ID | \
3666 VERBOSE_COMP_START | VERBOSE_COMP_END | \
3669 static inline bool has_any_comp_options(struct find_param *param)
3671 enum llapi_layout_verbose verbose = param->fp_verbose;
3673 if (param->fp_check_comp_id || param->fp_check_comp_count ||
3674 param->fp_check_comp_start || param->fp_check_comp_end ||
3675 param->fp_check_comp_flags)
3678 /* show full layout information, not component specific */
3679 if ((verbose & ~VERBOSE_DETAIL) == VERBOSE_DEFAULT)
3682 return verbose & VERBOSE_COMP_OPTS;
3685 struct lov_user_mds_data *lov_forge_comp_v1(struct lov_user_mds_data *orig,
3688 struct lov_user_md *lum = &orig->lmd_lmm;
3689 struct lov_user_mds_data *new;
3690 struct lov_comp_md_v1 *comp_v1;
3691 struct lov_comp_md_entry_v1 *ent;
3692 int lum_off = sizeof(*comp_v1) + sizeof(*ent);
3693 int lum_size = lov_user_md_size(is_dir ? 0 : lum->lmm_stripe_count,
3696 new = malloc(offsetof(typeof(*new), lmd_lmm) + lum_off + lum_size);
3698 llapi_printf(LLAPI_MSG_NORMAL, "out of memory\n");
3702 memcpy(new, orig, sizeof(new->lmd_stx) + sizeof(new->lmd_flags)
3703 + sizeof(new->lmd_lmmsize));
3705 comp_v1 = (struct lov_comp_md_v1 *)&new->lmd_lmm;
3706 comp_v1->lcm_magic = lum->lmm_magic;
3707 comp_v1->lcm_size = lum_off + lum_size;
3708 comp_v1->lcm_layout_gen = is_dir ? 0 : lum->lmm_layout_gen;
3709 comp_v1->lcm_flags = 0;
3710 comp_v1->lcm_entry_count = 1;
3712 ent = &comp_v1->lcm_entries[0];
3714 ent->lcme_flags = is_dir ? 0 : LCME_FL_INIT;
3715 ent->lcme_extent.e_start = 0;
3716 ent->lcme_extent.e_end = LUSTRE_EOF;
3717 ent->lcme_offset = lum_off;
3718 ent->lcme_size = lum_size;
3720 memcpy((char *)comp_v1 + lum_off, lum, lum_size);
3725 static void lov_dump_plain_user_lmm(struct find_param *param, char *path,
3726 enum lov_dump_flags flags)
3728 __u32 magic = *(__u32 *)¶m->fp_lmd->lmd_lmm;
3730 if (has_any_comp_options(param)) {
3731 struct lov_user_mds_data *new_lmd, *orig_lmd;
3733 orig_lmd = param->fp_lmd;
3734 new_lmd = lov_forge_comp_v1(orig_lmd, flags & LDF_IS_DIR);
3735 if (new_lmd != NULL) {
3736 param->fp_lmd = new_lmd;
3737 lov_dump_comp_v1(param, path, flags);
3738 param->fp_lmd = orig_lmd;
3744 if (magic == LOV_USER_MAGIC_V1) {
3745 lov_dump_user_lmm_v1v3(¶m->fp_lmd->lmd_lmm, NULL,
3746 param->fp_lmd->lmd_lmm.lmm_objects,
3747 path, param->fp_obd_index,
3748 param->fp_max_depth, param->fp_verbose,
3751 char pool_name[LOV_MAXPOOLNAME + 1];
3752 struct lov_user_ost_data_v1 *objects;
3753 struct lov_user_md_v3 *lmmv3 = (void *)¶m->fp_lmd->lmd_lmm;
3755 snprintf(pool_name, sizeof(pool_name), "%s",
3756 lmmv3->lmm_pool_name);
3757 objects = lmmv3->lmm_objects;
3758 lov_dump_user_lmm_v1v3(¶m->fp_lmd->lmd_lmm, pool_name,
3759 objects, path, param->fp_obd_index,
3760 param->fp_max_depth, param->fp_verbose,
3765 static uint32_t check_foreign_type(uint32_t foreign_type)
3769 for (i = 0; i < LU_FOREIGN_TYPE_UNKNOWN; i++) {
3770 if (lu_foreign_types[i].lft_name == NULL)
3772 if (foreign_type == lu_foreign_types[i].lft_type)
3776 return LU_FOREIGN_TYPE_UNKNOWN;
3779 static void lov_dump_foreign_lmm(struct find_param *param, char *path,
3780 enum lov_dump_flags flags)
3782 struct lov_foreign_md *lfm = (void *)¶m->fp_lmd->lmd_lmm;
3783 bool yaml = flags & LDF_YAML;
3785 if (!yaml && param->fp_depth && path)
3786 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
3788 if (param->fp_verbose & VERBOSE_DETAIL) {
3789 uint32_t type = check_foreign_type(lfm->lfm_type);
3791 llapi_printf(LLAPI_MSG_NORMAL, "lfm_magic: 0x%08X\n",
3793 llapi_printf(LLAPI_MSG_NORMAL, "lfm_length: %u\n",
3795 llapi_printf(LLAPI_MSG_NORMAL, "lfm_type: 0x%08X",
3797 if (type < LU_FOREIGN_TYPE_UNKNOWN)
3798 llapi_printf(LLAPI_MSG_NORMAL, " (%s)\n",
3799 lu_foreign_types[type].lft_name);
3801 llapi_printf(LLAPI_MSG_NORMAL, " (unknown)\n");
3803 llapi_printf(LLAPI_MSG_NORMAL, "lfm_flags: 0x%08X\n",
3806 llapi_printf(LLAPI_MSG_NORMAL, "lfm_value: '%.*s'\n",
3807 lfm->lfm_length, lfm->lfm_value);
3808 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3811 static void lmv_dump_foreign_lmm(struct find_param *param, char *path,
3812 enum lov_dump_flags flags)
3814 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)param->fp_lmv_md;
3815 bool yaml = flags & LDF_YAML;
3817 if (!yaml && param->fp_depth && path)
3818 llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
3820 if (param->fp_verbose & VERBOSE_DETAIL) {
3821 uint32_t type = check_foreign_type(lfm->lfm_type);
3823 llapi_printf(LLAPI_MSG_NORMAL, "lfm_magic: 0x%08X\n",
3825 llapi_printf(LLAPI_MSG_NORMAL, "lfm_length: %u\n",
3827 llapi_printf(LLAPI_MSG_NORMAL, "lfm_type: 0x%08X",
3829 if (type < LU_FOREIGN_TYPE_UNKNOWN)
3830 llapi_printf(LLAPI_MSG_NORMAL, " (%s)\n",
3831 lu_foreign_types[type].lft_name);
3833 llapi_printf(LLAPI_MSG_NORMAL, " (unknown)\n");
3835 llapi_printf(LLAPI_MSG_NORMAL, "lfm_flags: 0x%08X\n",
3838 llapi_printf(LLAPI_MSG_NORMAL, "lfm_value: '%.*s'\n",
3839 lfm->lfm_length, lfm->lfm_value);
3840 llapi_printf(LLAPI_MSG_NORMAL, "\n");
3843 static void llapi_lov_dump_user_lmm(struct find_param *param, char *path,
3844 enum lov_dump_flags flags)
3848 if (param->fp_get_lmv || param->fp_get_default_lmv)
3849 magic = (__u32)param->fp_lmv_md->lum_magic;
3851 magic = *(__u32 *)¶m->fp_lmd->lmd_lmm; /* lum->lmm_magic */
3854 flags |= LDF_IS_RAW;
3859 case LOV_USER_MAGIC_V1:
3860 case LOV_USER_MAGIC_V3:
3861 case LOV_USER_MAGIC_SPECIFIC:
3862 lov_dump_plain_user_lmm(param, path, flags);
3864 case LOV_USER_MAGIC_FOREIGN:
3865 lov_dump_foreign_lmm(param, path, flags);
3868 case LMV_USER_MAGIC: {
3869 char pool_name[LOV_MAXPOOLNAME + 1];
3870 struct lmv_user_md *lum;
3872 lum = (struct lmv_user_md *)param->fp_lmv_md;
3873 snprintf(pool_name, sizeof(pool_name), "%s",
3874 lum->lum_pool_name);
3875 lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index,
3876 param->fp_max_depth, param->fp_verbose,
3880 case LOV_USER_MAGIC_COMP_V1:
3881 lov_dump_comp_v1(param, path, flags);
3883 case LMV_MAGIC_FOREIGN:
3884 lmv_dump_foreign_lmm(param, path, flags);
3887 llapi_printf(LLAPI_MSG_NORMAL, "unknown lmm_magic: %#x "
3888 "(expecting one of %#x %#x %#x %#x)\n",
3889 *(__u32 *)¶m->fp_lmd->lmd_lmm,
3890 LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3,
3891 LMV_USER_MAGIC, LMV_MAGIC_V1);
3896 int llapi_file_get_stripe(const char *path, struct lov_user_md *lum)
3902 fname = strrchr(path, '/');
3904 /* It should be a file (or other non-directory) */
3905 if (fname == NULL) {
3906 dname = (char *)malloc(2);
3910 fname = (char *)path;
3912 dname = (char *)malloc(fname - path + 1);
3915 strncpy(dname, path, fname - path);
3916 dname[fname - path] = '\0';
3920 fd = open(dname, O_RDONLY | O_NONBLOCK);
3926 strcpy((char *)lum, fname);
3927 if (ioctl(fd, IOC_MDC_GETFILESTRIPE, (void *)lum) == -1)
3930 if (close(fd) == -1 && rc == 0)
3938 int llapi_file_lookup(int dirfd, const char *name)
3940 struct obd_ioctl_data data = { 0 };
3945 if (dirfd < 0 || name == NULL)
3948 data.ioc_version = OBD_IOCTL_VERSION;
3949 data.ioc_len = sizeof(data);
3950 data.ioc_inlbuf1 = (char *)name;
3951 data.ioc_inllen1 = strlen(name) + 1;
3953 rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
3955 llapi_error(LLAPI_MSG_ERROR, rc,
3956 "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
3961 rc = ioctl(dirfd, IOC_MDC_LOOKUP, buf);
3967 /* Check if the file time matches all the given criteria (e.g. --atime +/-N).
3968 * Return -1 or 1 if file timestamp does not or does match the given criteria
3969 * correspondingly. Return 0 if the MDS time is being checked and there are
3970 * attributes on OSTs and it is not yet clear if the timespamp matches.
3972 * If 0 is returned, we need to do another RPC to the OSTs to obtain the
3973 * updated timestamps. */
3974 static int find_time_check(struct find_param *param, int mds)
3976 struct lov_user_mds_data *lmd = param->fp_lmd;
3980 /* Check if file is accepted. */
3981 if (param->fp_atime) {
3982 rc2 = find_value_cmp(lmd->lmd_stx.stx_atime.tv_sec,
3983 param->fp_atime, param->fp_asign,
3984 param->fp_exclude_atime,
3985 param->fp_time_margin, mds);
3991 if (param->fp_mtime) {
3992 rc2 = find_value_cmp(lmd->lmd_stx.stx_mtime.tv_sec,
3993 param->fp_mtime, param->fp_msign,
3994 param->fp_exclude_mtime,
3995 param->fp_time_margin, mds);
3999 /* If the previous check matches, but this one is not yet clear,
4000 * we should return 0 to do an RPC on OSTs. */
4005 if (param->fp_ctime) {
4006 rc2 = find_value_cmp(lmd->lmd_stx.stx_ctime.tv_sec,
4007 param->fp_ctime, param->fp_csign,
4008 param->fp_exclude_ctime,
4009 param->fp_time_margin, mds);
4013 /* If the previous check matches, but this one is not yet clear,
4014 * we should return 0 to do an RPC on OSTs. */
4022 static int find_newerxy_check(struct find_param *param, int mds)
4024 struct lov_user_mds_data *lmd = param->fp_lmd;
4029 for (i = 0; i < 2; i++) {
4030 /* Check if file is accepted. */
4031 if (param->fp_newery[NEWERXY_ATIME][i]) {
4032 rc2 = find_value_cmp(lmd->lmd_stx.stx_atime.tv_sec,
4033 param->fp_newery[NEWERXY_ATIME][i],
4040 if (param->fp_newery[NEWERXY_MTIME][i]) {
4041 rc2 = find_value_cmp(lmd->lmd_stx.stx_mtime.tv_sec,
4042 param->fp_newery[NEWERXY_MTIME][i],
4048 * If the previous check matches, but this one is not
4049 * yet clear, we should return 0 to do an RPC on OSTs.
4055 if (param->fp_newery[NEWERXY_CTIME][i]) {
4056 rc2 = find_value_cmp(lmd->lmd_stx.stx_ctime.tv_sec,
4057 param->fp_newery[NEWERXY_CTIME][i],
4063 * If the previous check matches, but this one is not
4064 * yet clear, we should return 0 to do an RPC on OSTs.
4075 * Check whether the stripes matches the indexes user provided
4079 static int check_obd_match(struct find_param *param)
4081 struct lov_user_ost_data_v1 *objects;
4082 struct lov_comp_md_v1 *comp_v1 = NULL;
4083 struct lov_user_mds_data *lmd = param->fp_lmd;
4084 struct lov_user_md_v1 *v1 = &lmd->lmd_lmm;
4085 int i, j, k, count = 1;
4087 if (param->fp_obd_uuid && param->fp_obd_index == OBD_NOT_FOUND)
4090 if (!S_ISREG(lmd->lmd_stx.stx_mode))
4093 /* exclude foreign */
4094 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4095 return param->fp_exclude_obd;
4097 /* Only those files should be accepted, which have a
4098 * stripe on the specified OST. */
4099 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4100 comp_v1 = (struct lov_comp_md_v1 *)v1;
4101 count = comp_v1->lcm_entry_count;
4104 for (i = 0; i < count; i++) {
4106 v1 = lov_comp_entry(comp_v1, i);
4108 objects = lov_v1v3_objects(v1);
4110 for (j = 0; j < v1->lmm_stripe_count; j++) {
4111 if (comp_v1 && !(comp_v1->lcm_entries[i].lcme_flags &
4114 for (k = 0; k < param->fp_num_obds; k++) {
4115 if (param->fp_obd_indexes[k] ==
4116 objects[j].l_ost_idx)
4117 return !param->fp_exclude_obd;
4122 return param->fp_exclude_obd;
4125 static int check_mdt_match(struct find_param *param)
4129 if (param->fp_mdt_uuid && param->fp_mdt_index == OBD_NOT_FOUND)
4132 /* FIXME: For striped dir, we should get stripe information and check */
4133 for (i = 0; i < param->fp_num_mdts; i++) {
4134 if (param->fp_mdt_indexes[i] == param->fp_file_mdt_index)
4135 return !param->fp_exclude_mdt;
4138 if (param->fp_exclude_mdt)
4145 * Check whether the obd is active or not, if it is
4146 * not active, just print the object affected by this
4149 static int print_failed_tgt(struct find_param *param, char *path, int type)
4151 struct obd_statfs stat_buf;
4152 struct obd_uuid uuid_buf;
4155 if (type != LL_STATFS_LOV && type != LL_STATFS_LMV)
4158 memset(&stat_buf, 0, sizeof(struct obd_statfs));
4159 memset(&uuid_buf, 0, sizeof(struct obd_uuid));
4160 ret = llapi_obd_statfs(path, type,
4161 param->fp_obd_index, &stat_buf,
4164 llapi_error(LLAPI_MSG_NORMAL, ret, "obd_uuid: %s failed",
4165 param->fp_obd_uuid->uuid);
4170 static int find_check_stripe_size(struct find_param *param)
4172 struct lov_comp_md_v1 *comp_v1 = NULL;
4173 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4174 __u32 stripe_size = 0;
4175 int ret, i, count = 1;
4177 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4178 return param->fp_exclude_stripe_size ? 1 : -1;
4180 ret = param->fp_exclude_stripe_size ? 1 : -1;
4181 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4182 comp_v1 = (struct lov_comp_md_v1 *)v1;
4183 count = comp_v1->lcm_entry_count;
4186 for (i = 0; i < count; i++) {
4187 struct lov_comp_md_entry_v1 *ent;
4190 v1 = lov_comp_entry(comp_v1, i);
4192 ent = &comp_v1->lcm_entries[i];
4193 if (ent->lcme_flags & LCME_FL_EXTENSION)
4195 if (!(ent->lcme_flags & LCME_FL_INIT))
4198 stripe_size = v1->lmm_stripe_size;
4201 ret = find_value_cmp(stripe_size, param->fp_stripe_size,
4202 param->fp_stripe_size_sign,
4203 param->fp_exclude_stripe_size,
4204 param->fp_stripe_size_units, 0);
4209 static int find_check_ext_size(struct find_param *param)
4211 struct lov_comp_md_v1 *comp_v1;
4212 struct lov_user_md_v1 *v1;
4215 ret = param->fp_exclude_ext_size ? 1 : -1;
4216 comp_v1 = (struct lov_comp_md_v1 *)¶m->fp_lmd->lmd_lmm;
4217 if (comp_v1->lcm_magic != LOV_USER_MAGIC_COMP_V1)
4220 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
4221 struct lov_comp_md_entry_v1 *ent;
4223 v1 = lov_comp_entry(comp_v1, i);
4225 ent = &comp_v1->lcm_entries[i];
4226 if (!(ent->lcme_flags & LCME_FL_EXTENSION))
4229 ret = find_value_cmp(v1->lmm_stripe_size, param->fp_ext_size,
4230 param->fp_ext_size_sign,
4231 param->fp_exclude_ext_size,
4232 param->fp_ext_size_units, 0);
4233 /* If any ext_size matches */
4241 static __u32 find_get_stripe_count(struct find_param *param)
4243 struct lov_comp_md_v1 *comp_v1 = NULL;
4244 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4246 __u32 stripe_count = 0;
4248 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4251 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4252 comp_v1 = (struct lov_comp_md_v1 *)v1;
4253 count = comp_v1->lcm_entry_count;
4256 for (i = 0; i < count; i++) {
4258 struct lov_comp_md_entry_v1 *ent;
4260 v1 = lov_comp_entry(comp_v1, i);
4262 ent = &comp_v1->lcm_entries[i];
4263 if (!(ent->lcme_flags & LCME_FL_INIT))
4266 if (ent->lcme_flags & LCME_FL_EXTENSION)
4269 stripe_count = v1->lmm_stripe_count;
4272 return stripe_count;
4275 #define LOV_PATTERN_INVALID 0xFFFFFFFF
4277 static int find_check_layout(struct find_param *param)
4279 struct lov_comp_md_v1 *comp_v1 = NULL;
4280 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4282 bool found = false, valid = false;
4284 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4285 comp_v1 = (struct lov_comp_md_v1 *)v1;
4286 count = comp_v1->lcm_entry_count;
4289 for (i = 0; i < count; i++) {
4291 v1 = lov_comp_entry(comp_v1, i);
4293 /* foreign file have a special magic but no pattern field */
4294 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4297 if (v1->lmm_pattern == LOV_PATTERN_INVALID)
4301 if (v1->lmm_pattern & param->fp_layout) {
4310 if ((found && !param->fp_exclude_layout) ||
4311 (!found && param->fp_exclude_layout))
4317 /* if no type specified, check/exclude all foreign
4318 * if type specified, check all foreign&type and exclude !foreign + foreign&type
4320 static int find_check_foreign(struct find_param *param)
4322 if (S_ISREG(param->fp_lmd->lmd_stx.stx_mode)) {
4323 struct lov_foreign_md *lfm;
4325 lfm = (void *)¶m->fp_lmd->lmd_lmm;
4326 if (lfm->lfm_magic != LOV_USER_MAGIC_FOREIGN) {
4327 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN)
4328 return param->fp_exclude_foreign ? 1 : -1;
4331 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN ||
4332 lfm->lfm_type == param->fp_foreign_type)
4333 return param->fp_exclude_foreign ? -1 : 1;
4334 return param->fp_exclude_foreign ? 1 : -1;
4338 if (S_ISDIR(param->fp_lmd->lmd_stx.stx_mode)) {
4339 struct lmv_foreign_md *lfm;
4341 lfm = (void *)param->fp_lmv_md;
4342 if (lfm->lfm_magic != LMV_MAGIC_FOREIGN) {
4343 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN)
4344 return param->fp_exclude_foreign ? 1 : -1;
4347 if (param->fp_foreign_type == LU_FOREIGN_TYPE_UNKNOWN ||
4348 lfm->lfm_type == param->fp_foreign_type)
4349 return param->fp_exclude_foreign ? -1 : 1;
4350 return param->fp_exclude_foreign ? 1 : -1;
4356 static int find_check_pool(struct find_param *param)
4358 struct lov_comp_md_v1 *comp_v1 = NULL;
4359 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4360 struct lov_user_md_v3 *v3 = (void *)v1;
4364 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4365 comp_v1 = (struct lov_comp_md_v1 *)v1;
4366 count = comp_v1->lcm_entry_count;
4367 /* empty requested pool is taken as no pool search */
4368 if (count == 0 && param->fp_poolname[0] == '\0')
4372 for (i = 0; i < count; i++) {
4373 if (comp_v1 != NULL)
4374 v1 = lov_comp_entry(comp_v1, i);
4376 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4379 if (((v1->lmm_magic == LOV_USER_MAGIC_V1) &&
4380 (param->fp_poolname[0] == '\0')) ||
4381 ((v1->lmm_magic == LOV_USER_MAGIC_V3) &&
4382 (strncmp(v3->lmm_pool_name,
4383 param->fp_poolname, LOV_MAXPOOLNAME) == 0)) ||
4384 ((v1->lmm_magic == LOV_USER_MAGIC_V3) &&
4385 (strcmp(param->fp_poolname, "*") == 0))) {
4391 if ((found && !param->fp_exclude_pool) ||
4392 (!found && param->fp_exclude_pool))
4398 static int find_check_comp_options(struct find_param *param)
4400 struct lov_comp_md_v1 *comp_v1, *forged_v1 = NULL;
4401 struct lov_user_mds_data *lmd = param->fp_lmd;
4402 struct lov_user_md_v1 *v1 = &lmd->lmd_lmm;
4403 struct lov_comp_md_entry_v1 *entry;
4406 if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
4409 if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
4410 comp_v1 = (struct lov_comp_md_v1 *)v1;
4412 forged_v1 = malloc(sizeof(*forged_v1) + sizeof(*entry));
4413 if (forged_v1 == NULL)
4415 comp_v1 = forged_v1;
4416 comp_v1->lcm_entry_count = 1;
4417 entry = &comp_v1->lcm_entries[0];
4418 entry->lcme_flags = S_ISDIR(lmd->lmd_stx.stx_mode) ?
4420 entry->lcme_extent.e_start = 0;
4421 entry->lcme_extent.e_end = LUSTRE_EOF;
4424 /* invalid case, don't match for any kind of search. */
4425 if (comp_v1->lcm_entry_count == 0) {
4430 if (param->fp_check_comp_count) {
4431 ret = find_value_cmp(forged_v1 ? 0 : comp_v1->lcm_entry_count,
4432 param->fp_comp_count,
4433 param->fp_comp_count_sign,
4434 param->fp_exclude_comp_count, 1, 0);
4440 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
4441 entry = &comp_v1->lcm_entries[i];
4443 if (param->fp_check_comp_flags) {
4445 if (((param->fp_comp_flags & entry->lcme_flags) !=
4446 param->fp_comp_flags) ||
4447 (param->fp_comp_neg_flags & entry->lcme_flags)) {
4453 if (param->fp_check_comp_start) {
4454 ret = find_value_cmp(entry->lcme_extent.e_start,
4455 param->fp_comp_start,
4456 param->fp_comp_start_sign,
4457 param->fp_exclude_comp_start,
4458 param->fp_comp_start_units, 0);
4463 if (param->fp_check_comp_end) {
4464 ret = find_comp_end_cmp(entry->lcme_extent.e_end,
4470 /* the component matches all criteria */
4479 static int find_check_mirror_options(struct find_param *param)
4481 struct lov_comp_md_v1 *comp_v1;
4482 struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
4485 if (v1->lmm_magic != LOV_USER_MAGIC_COMP_V1)
4488 comp_v1 = (struct lov_comp_md_v1 *)v1;
4490 if (param->fp_check_mirror_count) {
4491 ret = find_value_cmp(comp_v1->lcm_mirror_count + 1,
4492 param->fp_mirror_count,
4493 param->fp_mirror_count_sign,
4494 param->fp_exclude_mirror_count, 1, 0);
4499 if (param->fp_check_mirror_state) {
4501 __u16 file_state = comp_v1->lcm_flags & LCM_FL_FLR_MASK;
4503 if ((param->fp_mirror_state != 0 &&
4504 file_state != param->fp_mirror_state) ||
4505 file_state == param->fp_mirror_neg_state)
4512 static bool find_check_lmm_info(struct find_param *param)
4514 return param->fp_check_pool || param->fp_check_stripe_count ||
4515 param->fp_check_stripe_size || param->fp_check_layout ||
4516 param->fp_check_comp_count || param->fp_check_comp_end ||
4517 param->fp_check_comp_start || param->fp_check_comp_flags ||
4518 param->fp_check_mirror_count || param->fp_check_foreign ||
4519 param->fp_check_mirror_state || param->fp_check_ext_size ||
4520 param->fp_check_projid;
4524 * Get file/directory project id.
4525 * by the open fd resides on.
4526 * Return 0 and project id on success, or -ve errno.
4528 static int fget_projid(int fd, int *projid)
4533 rc = ioctl(fd, LL_IOC_FSGETXATTR, &fsx);
4537 *projid = fsx.fsx_projid;
4541 static int cb_find_init(char *path, DIR *parent, DIR **dirp,
4542 void *data, struct dirent64 *de)
4544 struct find_param *param = (struct find_param *)data;
4545 struct lov_user_mds_data *lmd = param->fp_lmd;
4546 DIR *dir = dirp == NULL ? NULL : *dirp;
4547 int decision = 1; /* 1 is accepted; -1 is rejected. */
4549 int checked_type = 0;
4551 __u32 stripe_count = 0;
4555 if (parent == NULL && dir == NULL)
4558 /* If a regular expression is presented, make the initial decision */
4559 if (param->fp_pattern != NULL) {
4560 char *fname = strrchr(path, '/');
4561 fname = (fname == NULL ? path : fname + 1);
4562 ret = fnmatch(param->fp_pattern, fname, 0);
4563 if ((ret == FNM_NOMATCH && !param->fp_exclude_pattern) ||
4564 (ret == 0 && param->fp_exclude_pattern))
4568 /* See if we can check the file type from the dirent. */
4569 if (param->fp_type != 0 && de != NULL && de->d_type != DT_UNKNOWN) {
4572 if (DTTOIF(de->d_type) == param->fp_type) {
4573 if (param->fp_exclude_type)
4576 if (!param->fp_exclude_type)
4583 /* Request MDS for the stat info if some of these parameters need
4584 * to be compared. */
4585 if (param->fp_obd_uuid || param->fp_mdt_uuid ||
4586 param->fp_check_uid || param->fp_check_gid || param->fp_newerxy ||
4587 param->fp_atime || param->fp_mtime || param->fp_ctime ||
4588 param->fp_check_size || param->fp_check_blocks ||
4589 find_check_lmm_info(param) ||
4590 param->fp_check_mdt_count || param->fp_check_hash_type)
4593 if (param->fp_type != 0 && checked_type == 0)
4596 if (decision == 0) {
4597 if (dir && (param->fp_check_mdt_count ||
4598 param->fp_check_hash_type || param->fp_check_foreign)) {
4599 param->fp_get_lmv = 1;
4600 ret = cb_get_dirstripe(path, dir, param);
4602 /* XXX this works to decide for foreign
4605 if (errno == ENODATA &&
4606 param->fp_check_foreign) {
4607 if (param->fp_exclude_foreign)
4615 param->fp_lmd->lmd_lmm.lmm_magic = 0;
4616 ret = get_lmd_info(path, parent, dir, param->fp_lmd,
4617 param->fp_lum_size, GET_LMD_INFO);
4618 if (ret == 0 && param->fp_lmd->lmd_lmm.lmm_magic == 0 &&
4619 find_check_lmm_info(param)) {
4620 struct lov_user_md *lmm = ¶m->fp_lmd->lmd_lmm;
4622 /* We need to "fake" the "use the default" values
4623 * since the lmm struct is zeroed out at this point. */
4624 lmm->lmm_magic = LOV_USER_MAGIC_V1;
4625 lmm->lmm_pattern = LOV_PATTERN_DEFAULT;
4627 ostid_set_seq(&lmm->lmm_oi,
4628 FID_SEQ_LOV_DEFAULT);
4629 lmm->lmm_stripe_size = 0;
4630 lmm->lmm_stripe_count = 0;
4631 lmm->lmm_stripe_offset = -1;
4633 if (ret == 0 && param->fp_mdt_uuid != NULL) {
4635 ret = llapi_file_fget_mdtidx(dirfd(dir),
4636 ¶m->fp_file_mdt_index);
4637 } else if (S_ISREG(lmd->lmd_stx.stx_mode)) {
4638 /* FIXME: we could get the MDT index from the
4639 * file's FID in lmd->lmd_lmm.lmm_oi without
4640 * opening the file, once we are sure that
4641 * LFSCK2 (2.6) has fixed up pre-2.0 LOV EAs.
4642 * That would still be an ioctl() to map the
4643 * FID to the MDT, but not an open RPC. */
4644 fd = open(path, O_RDONLY);
4646 ret = llapi_file_fget_mdtidx(fd,
4647 ¶m->fp_file_mdt_index);
4652 /* For a special file, we assume it resides on
4653 * the same MDT as the parent directory. */
4654 ret = llapi_file_fget_mdtidx(dirfd(parent),
4655 ¶m->fp_file_mdt_index);
4666 stripe_count = find_get_stripe_count(param);
4670 if (param->fp_type && !checked_type) {
4671 if ((lmd->lmd_stx.stx_mode & S_IFMT) == param->fp_type) {
4672 if (param->fp_exclude_type)
4675 if (!param->fp_exclude_type)
4681 if (param->fp_obd_uuid || param->fp_mdt_uuid) {
4682 if (lustre_fs && param->fp_got_uuids &&
4683 param->fp_dev != makedev(lmd->lmd_stx.stx_dev_major,
4684 lmd->lmd_stx.stx_dev_minor)) {
4685 /* A lustre/lustre mount point is crossed. */
4686 param->fp_got_uuids = 0;
4687 param->fp_obds_printed = 0;
4688 param->fp_mdt_index = OBD_NOT_FOUND;
4689 param->fp_obd_index = OBD_NOT_FOUND;
4692 if (lustre_fs && !param->fp_got_uuids) {
4693 ret = setup_target_indexes(dir ? dir : parent, path,
4698 param->fp_dev = makedev(lmd->lmd_stx.stx_dev_major,
4699 lmd->lmd_stx.stx_dev_minor);
4700 } else if (!lustre_fs && param->fp_got_uuids) {
4701 /* A lustre/non-lustre mount point is crossed. */
4702 param->fp_got_uuids = 0;
4703 param->fp_mdt_index = OBD_NOT_FOUND;
4704 param->fp_obd_index = OBD_NOT_FOUND;
4708 if (param->fp_check_foreign) {
4709 decision = find_check_foreign(param);
4714 if (param->fp_check_stripe_size) {
4715 decision = find_check_stripe_size(param);
4720 if (param->fp_check_ext_size) {
4721 decision = find_check_ext_size(param);
4726 if (param->fp_check_stripe_count) {
4727 decision = find_value_cmp(stripe_count, param->fp_stripe_count,
4728 param->fp_stripe_count_sign,
4729 param->fp_exclude_stripe_count, 1, 0);
4734 if (param->fp_check_mdt_count) {
4735 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
4740 decision = find_value_cmp(
4741 param->fp_lmv_md->lum_stripe_count,
4742 param->fp_mdt_count,
4743 param->fp_mdt_count_sign,
4744 param->fp_exclude_mdt_count, 1, 0);
4749 if (param->fp_check_layout) {
4750 decision = find_check_layout(param);
4755 if (param->fp_check_hash_type) {
4758 if (param->fp_lmv_md->lum_magic == LMV_MAGIC_FOREIGN) {
4763 found = param->fp_lmv_md->lum_hash_type & param->fp_hash_type;
4764 if ((found && param->fp_exclude_hash_type) ||
4765 (!found && !param->fp_exclude_hash_type)) {
4771 /* If an OBD UUID is specified but none matches, skip this file. */
4772 if ((param->fp_obd_uuid && param->fp_obd_index == OBD_NOT_FOUND) ||
4773 (param->fp_mdt_uuid && param->fp_mdt_index == OBD_NOT_FOUND))
4776 /* If an OST or MDT UUID is given, and some OST matches,
4778 if (param->fp_obd_index != OBD_NOT_FOUND ||
4779 param->fp_mdt_index != OBD_NOT_FOUND) {
4780 if (param->fp_obd_uuid) {
4781 if (check_obd_match(param)) {
4782 /* If no mdtuuid is given, we are done.
4783 * Otherwise, fall through to the mdtuuid
4785 if (!param->fp_mdt_uuid)
4792 if (param->fp_mdt_uuid) {
4793 if (check_mdt_match(param))
4800 if (param->fp_check_uid) {
4801 if (lmd->lmd_stx.stx_uid == param->fp_uid) {
4802 if (param->fp_exclude_uid)
4805 if (!param->fp_exclude_uid)
4810 if (param->fp_check_gid) {
4811 if (lmd->lmd_stx.stx_gid == param->fp_gid) {
4812 if (param->fp_exclude_gid)
4815 if (!param->fp_exclude_gid)
4820 if (param->fp_check_projid) {
4824 fd = open(path, O_RDONLY);
4827 ret = fget_projid(fd, &projid);
4832 if (projid == param->fp_projid) {
4833 if (param->fp_exclude_projid)
4836 if (!param->fp_exclude_projid)
4841 if (param->fp_check_pool) {
4842 decision = find_check_pool(param);
4847 if (param->fp_check_comp_count || param->fp_check_comp_flags ||
4848 param->fp_check_comp_start || param->fp_check_comp_end) {
4849 decision = find_check_comp_options(param);
4854 if (param->fp_check_mirror_count || param->fp_check_mirror_state) {
4855 decision = find_check_mirror_options(param);
4860 /* Check the time on mds. */
4862 if (param->fp_atime || param->fp_mtime || param->fp_ctime) {
4865 for_mds = lustre_fs ?
4866 (S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) : 0;
4867 decision = find_time_check(param, for_mds);
4872 if (param->fp_newerxy) {
4875 for_mds = lustre_fs ?
4876 (S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) : 0;
4877 decision = find_newerxy_check(param, for_mds);
4882 flags = param->fp_lmd->lmd_flags;
4883 if (param->fp_check_size &&
4884 ((S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) ||
4885 S_ISDIR(lmd->lmd_stx.stx_mode)) &&
4886 !(flags & OBD_MD_FLSIZE ||
4887 (param->fp_lazy && flags & OBD_MD_FLLAZYSIZE)))
4890 if (param->fp_check_blocks &&
4891 ((S_ISREG(lmd->lmd_stx.stx_mode) && stripe_count) ||
4892 S_ISDIR(lmd->lmd_stx.stx_mode)) &&
4893 !(flags & OBD_MD_FLBLOCKS ||
4894 (param->fp_lazy && flags & OBD_MD_FLLAZYBLOCKS)))
4897 /* If file still fits the request, ask ost for updated info.
4898 * The regular stat is almost of the same speed as some new
4899 * 'glimpse-size-ioctl'.
4904 /* For regular files with the stripe the decision may have not
4905 * been taken yet if *time or size is to be checked. */
4906 if (param->fp_obd_index != OBD_NOT_FOUND)
4907 print_failed_tgt(param, path, LL_STATFS_LOV);
4909 if (param->fp_mdt_index != OBD_NOT_FOUND)
4910 print_failed_tgt(param, path, LL_STATFS_LMV);
4913 ret = fstat_f(dirfd(dir), &st);
4914 else if (de != NULL)
4915 ret = fstatat_f(dirfd(parent), de->d_name, &st,
4916 AT_SYMLINK_NOFOLLOW);
4918 ret = lstat_f(path, &st);
4921 if (errno == ENOENT) {
4922 llapi_error(LLAPI_MSG_ERROR, -ENOENT,
4923 "warning: %s: %s does not exist",
4928 llapi_error(LLAPI_MSG_ERROR, ret,
4929 "%s: stat on %s failed",
4935 convert_lmd_statx(param->fp_lmd, &st, true);
4936 /* Check the time on osc. */
4937 decision = find_time_check(param, 0);
4941 if (param->fp_newerxy) {
4942 decision = find_newerxy_check(param, 0);
4949 if (param->fp_check_size) {
4950 decision = find_value_cmp(lmd->lmd_stx.stx_size,
4952 param->fp_size_sign,
4953 param->fp_exclude_size,
4954 param->fp_size_units, 0);
4959 if (param->fp_check_blocks) { /* convert st_blocks to bytes */
4960 decision = find_value_cmp(lmd->lmd_stx.stx_blocks * 512,
4962 param->fp_blocks_sign,
4963 param->fp_exclude_blocks,
4964 param->fp_blocks_units, 0);
4970 llapi_printf(LLAPI_MSG_NORMAL, "%s", path);
4971 if (param->fp_zero_end)
4972 llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0');
4974 llapi_printf(LLAPI_MSG_NORMAL, "\n");
4978 /* Do not get down anymore? */
4979 if (param->fp_depth == param->fp_max_depth) {
4990 static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
4991 void *param_data, struct dirent64 *de)
4993 struct find_param *param = (struct find_param *)param_data;
4994 struct lmv_user_md *lmu = param->fp_lmv_md;
4995 DIR *tmp_parent = parent;
4996 char raw[MAX_IOC_BUFLEN] = {'\0'};
4998 struct obd_ioctl_data data = { 0 };
5005 if (parent == NULL && dirp == NULL)
5014 if (parent == NULL) {
5015 tmp_parent = opendir_parent(path);
5016 if (tmp_parent == NULL) {
5019 llapi_error(LLAPI_MSG_ERROR, ret,
5020 "can not open %s", path);
5025 fd = dirfd(tmp_parent);
5027 path_copy = strdup(path);
5028 filename = basename(path_copy);
5030 data.ioc_inlbuf1 = (char *)filename;
5031 data.ioc_inllen1 = strlen(filename) + 1;
5032 data.ioc_inlbuf2 = (char *)lmu;
5033 data.ioc_inllen2 = lmv_user_md_size(lmu->lum_stripe_count,
5035 ret = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
5037 llapi_error(LLAPI_MSG_ERROR, ret,
5038 "llapi_obd_statfs: error packing ioctl data");
5043 ret = ioctl(fd, LL_IOC_MIGRATE, rawbuf);
5045 if (errno == EBUSY && !retry) {
5046 /* because migrate may not be able to lock all involved
5047 * objects in order, for some of them it try lock, while
5048 * there may be conflicting COS locks and cause migrate
5049 * fail with EBUSY, hope a sync() could cause
5050 * transaction commit and release these COS locks. */
5054 } else if (errno == EALREADY) {
5055 if (param->fp_verbose & VERBOSE_DETAIL)
5056 llapi_printf(LLAPI_MSG_NORMAL,
5057 "%s migrated to MDT%d already\n",
5058 path, lmu->lum_stripe_offset);
5062 llapi_error(LLAPI_MSG_ERROR, ret, "%s migrate failed",
5066 } else if (param->fp_verbose & VERBOSE_DETAIL) {
5067 llapi_printf(LLAPI_MSG_NORMAL,
5068 "migrate %s to MDT%d stripe count %d\n",
5069 path, lmu->lum_stripe_offset,
5070 lmu->lum_stripe_count);
5075 /* If the directory is being migration, we need
5076 * close the directory after migration,
5077 * so the old directory cache will be cleanup
5078 * on the client side, and re-open to get the
5079 * new directory handle */
5080 *dirp = opendir(path);
5081 if (*dirp == NULL) {
5083 llapi_error(LLAPI_MSG_ERROR, ret,
5084 "%s: Failed to open '%s'", __func__, path);
5089 closedir(tmp_parent);
5096 /* dir migration finished, shrink its stripes */
5097 static int cb_migrate_mdt_fini(char *path, DIR *parent, DIR **dirp, void *data,
5098 struct dirent64 *de)
5100 struct find_param *param = data;
5101 struct lmv_user_md *lmu = param->fp_lmv_md;
5102 int lmulen = lmv_user_md_size(lmu->lum_stripe_count, lmu->lum_magic);
5105 if (de && de->d_type != DT_DIR)
5110 * close it before setxattr because the latter may destroy the
5111 * original object, and cause close fail.
5113 ret = closedir(*dirp);
5119 ret = setxattr(path, XATTR_NAME_LMV, lmu, lmulen, 0);
5120 if (ret == -EALREADY)
5123 cb_common_fini(path, parent, dirp, data, de);
5127 int llapi_migrate_mdt(char *path, struct find_param *param)
5129 return param_callback(path, cb_migrate_mdt_init, cb_migrate_mdt_fini,
5133 int llapi_mv(char *path, struct find_param *param)
5135 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 59, 0)
5136 static bool printed;
5139 llapi_error(LLAPI_MSG_ERROR, -ESTALE,
5140 "%s() is deprecated, use llapi_migrate_mdt() instead",
5145 return llapi_migrate_mdt(path, param);
5148 int llapi_find(char *path, struct find_param *param)
5150 return param_callback(path, cb_find_init, cb_common_fini, param);
5154 * Get MDT number that the file/directory inode referenced
5155 * by the open fd resides on.
5156 * Return 0 and mdtidx on success, or -ve errno.
5158 int llapi_file_fget_mdtidx(int fd, int *mdtidx)
5160 if (ioctl(fd, LL_IOC_GET_MDTIDX, mdtidx) < 0)
5165 static int cb_get_mdt_index(char *path, DIR *parent, DIR **dirp, void *data,
5166 struct dirent64 *de)
5168 struct find_param *param = (struct find_param *)data;
5169 DIR *d = dirp == NULL ? NULL : *dirp;
5173 if (parent == NULL && d == NULL)
5177 ret = llapi_file_fget_mdtidx(dirfd(d), &mdtidx);
5178 } else /* if (parent) */ {
5181 fd = open(path, O_RDONLY | O_NOCTTY);
5183 ret = llapi_file_fget_mdtidx(fd, &mdtidx);
5191 if (ret == -ENODATA) {
5192 if (!param->fp_obd_uuid)
5193 llapi_printf(LLAPI_MSG_NORMAL,
5194 "'%s' has no stripe info\n", path);
5196 } else if (ret == -ENOENT) {
5197 llapi_error(LLAPI_MSG_WARN, ret,
5198 "warning: %s: '%s' does not exist",
5201 } else if (ret == -ENOTTY) {
5202 llapi_error(LLAPI_MSG_ERROR, ret,
5203 "%s: '%s' not on a Lustre fs",
5206 llapi_error(LLAPI_MSG_ERROR, ret,
5207 "error: %s: '%s' failed get_mdtidx",
5213 if (param->fp_quiet || !(param->fp_verbose & VERBOSE_DETAIL))
5214 llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx);
5216 llapi_printf(LLAPI_MSG_NORMAL, "%s\nmdt_index:\t%d\n",
5220 /* Do not go down anymore? */
5221 if (param->fp_depth == param->fp_max_depth)
5229 static int cb_getstripe(char *path, DIR *parent, DIR **dirp, void *data,
5230 struct dirent64 *de)
5232 struct find_param *param = (struct find_param *)data;
5233 DIR *d = dirp == NULL ? NULL : *dirp;
5236 if (parent == NULL && d == NULL)
5239 if (param->fp_obd_uuid) {
5240 param->fp_quiet = 1;
5241 ret = setup_obd_uuid(d ? dirfd(d) : dirfd(parent), path, param);
5246 if (d && (param->fp_get_lmv || param->fp_get_default_lmv))
5247 ret = cb_get_dirstripe(path, d, param);
5249 (parent && !param->fp_get_lmv && !param->fp_get_default_lmv))
5250 ret = get_lmd_info(path, parent, d, ¶m->fp_lmd->lmd_lmm,
5251 param->fp_lum_size, GET_LMD_STRIPE);
5256 if (errno == ENODATA && d != NULL) {
5257 /* We need to "fake" the "use the default" values
5258 * since the lmm struct is zeroed out at this point.
5259 * The magic needs to be set in order to satisfy
5260 * a check later on in the code path.
5261 * The object_seq needs to be set for the "(Default)"
5262 * prefix to be displayed. */
5263 if (param->fp_get_default_lmv) {
5264 struct lmv_user_md *lum = param->fp_lmv_md;
5266 lum->lum_magic = LMV_USER_MAGIC;
5267 lum->lum_stripe_count = 0;
5268 lum->lum_stripe_offset = LMV_OFFSET_DEFAULT;
5270 } else if (param->fp_get_lmv) {
5271 struct lmv_user_md *lum = param->fp_lmv_md;
5274 ret = llapi_file_fget_mdtidx(dirfd(d), &mdtidx);
5277 lum->lum_magic = LMV_MAGIC_V1;
5278 lum->lum_stripe_count = 0;
5279 lum->lum_stripe_offset = mdtidx;
5282 struct lov_user_md *lmm =
5283 ¶m->fp_lmd->lmd_lmm;
5285 lmm->lmm_magic = LOV_USER_MAGIC_V1;
5287 ostid_set_seq(&lmm->lmm_oi,
5288 FID_SEQ_LOV_DEFAULT);
5289 lmm->lmm_stripe_count = 0;
5290 lmm->lmm_stripe_size = 0;
5291 lmm->lmm_stripe_offset = -1;
5294 } else if (errno == ENODATA && parent != NULL) {
5295 if (!param->fp_obd_uuid && !param->fp_mdt_uuid)
5296 llapi_printf(LLAPI_MSG_NORMAL,
5297 "%s has no stripe info\n", path);
5299 } else if (errno == ENOENT) {
5300 llapi_error(LLAPI_MSG_WARN, -ENOENT,
5301 "warning: %s: %s does not exist",
5304 } else if (errno == ENOTTY) {
5306 llapi_error(LLAPI_MSG_ERROR, ret,
5307 "%s: '%s' not on a Lustre fs?",
5312 llapi_error(LLAPI_MSG_ERROR, ret,
5313 "error: %s: %s failed for %s",
5314 __func__, d ? "LL_IOC_LOV_GETSTRIPE" :
5315 "IOC_MDC_GETFILESTRIPE", path);
5322 if (!(param->fp_verbose & VERBOSE_MDTINDEX))
5323 llapi_lov_dump_user_lmm(param, path, d ? LDF_IS_DIR : 0);
5326 /* Do not get down anymore? */
5327 if (param->fp_depth == param->fp_max_depth)
5335 int llapi_getstripe(char *path, struct find_param *param)
5337 return param_callback(path, (param->fp_verbose & VERBOSE_MDTINDEX) ?
5338 cb_get_mdt_index : cb_getstripe,
5339 cb_common_fini, param);
5342 int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
5343 struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
5345 char raw[MAX_IOC_BUFLEN] = {'\0'};
5347 struct obd_ioctl_data data = { 0 };
5350 data.ioc_inlbuf1 = (char *)&type;
5351 data.ioc_inllen1 = sizeof(__u32);
5352 data.ioc_inlbuf2 = (char *)&index;
5353 data.ioc_inllen2 = sizeof(__u32);
5354 data.ioc_pbuf1 = (char *)stat_buf;
5355 data.ioc_plen1 = sizeof(struct obd_statfs);
5356 data.ioc_pbuf2 = (char *)uuid_buf;
5357 data.ioc_plen2 = sizeof(struct obd_uuid);
5359 rc = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
5361 llapi_error(LLAPI_MSG_ERROR, rc,
5362 "llapi_obd_statfs: error packing ioctl data");
5366 rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
5368 return rc < 0 ? -errno : 0;
5371 int llapi_obd_statfs(char *path, __u32 type, __u32 index,
5372 struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf)
5377 fd = open(path, O_RDONLY);
5380 llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'",
5382 /* If we can't even open a file on the filesystem (e.g. with
5383 * -ESHUTDOWN), force caller to exit or it will loop forever. */
5387 rc = llapi_obd_fstatfs(fd, type, index, stat_buf, uuid_buf);
5394 #define MAX_STRING_SIZE 128
5396 int llapi_ping(char *obd_type, char *obd_name)
5398 int flags = O_RDONLY;
5399 char buf[1] = { 0 };
5403 rc = cfs_get_param_paths(&path, "%s/%s/ping",
5404 obd_type, obd_name);
5408 fd = open(path.gl_pathv[0], flags);
5410 if (errno == EACCES && flags == O_RDONLY) {
5415 llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s",
5420 if (flags == O_RDONLY)
5421 rc = read(fd, buf, sizeof(buf));
5423 rc = write(fd, buf, sizeof(buf));
5431 cfs_free_param_data(&path);
5435 int llapi_target_iterate(int type_num, char **obd_type,
5436 void *args, llapi_cb_t cb)
5442 for (i = 0; i < type_num; i++) {
5445 rc = cfs_get_param_paths(¶m, "%s/*/uuid", obd_type[i]);
5449 for (j = 0; j < param.gl_pathc; j++) {
5450 char obd_uuid[UUID_MAX + 1];
5454 fp = fopen(param.gl_pathv[j], "r");
5457 llapi_error(LLAPI_MSG_ERROR, rc,
5458 "error: opening '%s'",
5463 if (fgets(obd_uuid, sizeof(obd_uuid), fp) == NULL) {
5465 llapi_error(LLAPI_MSG_ERROR, rc,
5466 "error: reading '%s'",
5471 /* Extract the obd_name from the sysfs path.
5472 * 'topsysfs'/fs/lustre/'obd_type'/'obd_name'.
5474 obd_name = strstr(param.gl_pathv[j], "/fs/lustre/");
5480 /* skip /fs/lustre/'obd_type'/ */
5481 obd_name += strlen(obd_type[i]) + 12;
5482 /* chop off after obd_name */
5483 ptr = strrchr(obd_name, '/');
5487 cb(obd_type[i], obd_name, obd_uuid, args);
5496 cfs_free_param_data(¶m);
5500 static void do_target_check(char *obd_type_name, char *obd_name,
5501 char *obd_uuid, void *args)
5505 rc = llapi_ping(obd_type_name, obd_name);
5506 if (rc == ENOTCONN) {
5507 llapi_printf(LLAPI_MSG_NORMAL, "%s inactive.\n", obd_name);
5509 llapi_error(LLAPI_MSG_ERROR, rc, "error: check '%s'", obd_name);
5511 llapi_printf(LLAPI_MSG_NORMAL, "%s active.\n", obd_name);
5515 int llapi_target_check(int type_num, char **obd_type, char *dir)
5517 return llapi_target_iterate(type_num, obd_type, NULL, do_target_check);
5520 #undef MAX_STRING_SIZE
5522 /* Is this a lustre fs? */
5523 int llapi_is_lustre_mnttype(const char *type)
5525 return strcmp(type, "lustre") == 0 || strcmp(type, "lustre_tgt") == 0;
5528 /* Is this a lustre client fs? */
5529 int llapi_is_lustre_mnt(struct mntent *mnt)
5531 return (llapi_is_lustre_mnttype(mnt->mnt_type) &&
5532 strstr(mnt->mnt_fsname, ":/") != NULL);
5535 int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
5537 char fsname[PATH_MAX + 1];
5541 rc = llapi_search_fsname(mnt, fsname);
5545 root = open(mnt, O_RDONLY | O_DIRECTORY);
5548 llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", mnt);
5552 rc = ioctl(root, OBD_IOC_QUOTACTL, qctl);
5560 int llapi_get_connect_flags(const char *mnt, __u64 *flags)
5565 root = open(mnt, O_RDONLY | O_DIRECTORY);
5568 llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
5572 rc = ioctl(root, LL_IOC_GET_CONNECT_FLAGS, flags);
5575 llapi_error(LLAPI_MSG_ERROR, rc,
5576 "ioctl on %s for getting connect flags failed", mnt);
5583 * Get a 64-bit value representing the version of file data pointed by fd.
5585 * Each write or truncate, flushed on OST, will change this value. You can use
5586 * this value to verify if file data was modified. This only checks the file
5587 * data, not metadata.
5589 * \param flags 0: no flush pages, usually used it the process has already
5591 * LL_DV_RD_FLUSH: OSTs will take LCK_PR to flush dirty pages
5593 * LL_DV_WR_FLUSH: OSTs will take LCK_PW to flush all caching
5594 * pages from clients.
5596 * \retval 0 on success.
5597 * \retval -errno on error.
5599 int llapi_get_data_version(int fd, __u64 *data_version, __u64 flags)
5602 struct ioc_data_version idv;
5604 idv.idv_flags = (__u32)flags;
5606 rc = ioctl(fd, LL_IOC_DATA_VERSION, &idv);
5610 *data_version = idv.idv_version;
5616 * Flush cached pages from all clients.
5618 * \param fd File descriptor
5622 int llapi_file_flush(int fd)
5626 return llapi_get_data_version(fd, &dv, LL_DV_WR_FLUSH);
5630 * Fetch layout version from OST objects. Layout version on OST objects are
5631 * only set when the file is a mirrored file AND after the file has been
5632 * written at least once.
5634 * It actually fetches the least layout version from the objects.
5636 int llapi_get_ost_layout_version(int fd, __u32 *layout_version)
5639 struct ioc_data_version idv = { 0 };
5641 rc = ioctl(fd, LL_IOC_DATA_VERSION, &idv);
5645 *layout_version = idv.idv_layout_version;
5651 * Create a file without any name and open it for read/write
5653 * - file is created as if it were a standard file in the given \a directory
5654 * - file does not appear in \a directory and mtime does not change because
5655 * the filename is handled specially by the Lustre MDS.
5656 * - file is destroyed at final close
5658 * \param[in] directory directory from which to inherit layout/MDT idx
5659 * \param[in] mdt_idx MDT index on which the file is created,
5660 * \a idx == -1 means no specific MDT is requested
5661 * \param[in] mode standard open(2) mode
5662 * \param[in] stripe_param stripe parameters. May be NULL.
5664 * \retval a file descriptor on success.
5665 * \retval -errno on error.
5667 int llapi_create_volatile_param(const char *directory, int mdt_idx,
5668 int open_flags, mode_t mode,
5669 const struct llapi_stripe_param *stripe_param)
5671 char file_path[PATH_MAX];
5672 int saved_errno = errno;
5674 unsigned int rnumber;
5680 rc = snprintf(file_path, sizeof(file_path),
5681 "%s/" LUSTRE_VOLATILE_HDR "::%.4X",
5682 directory, rnumber);
5684 rc = snprintf(file_path, sizeof(file_path),
5685 "%s/" LUSTRE_VOLATILE_HDR ":%.4X:%.4X",
5686 directory, mdt_idx, rnumber);
5688 if (rc < 0 || rc >= sizeof(file_path))
5689 return -ENAMETOOLONG;
5692 * Either open O_WRONLY or O_RDWR, creating RDONLY
5693 * is non-sensical here
5695 if ((open_flags & O_ACCMODE) == O_RDONLY)
5696 open_flags = O_RDWR | (open_flags & ~O_ACCMODE);
5698 open_flags |= O_CREAT | O_EXCL | O_NOFOLLOW;
5700 if (stripe_param != NULL) {
5701 fd = llapi_file_open_param(file_path, open_flags,
5702 mode, stripe_param);
5706 fd = open(file_path, open_flags, mode);
5710 } while (fd < 0 && rc == -EEXIST);
5713 llapi_error(LLAPI_MSG_ERROR, rc,
5714 "Cannot create volatile file '%s' in '%s'",
5715 file_path + strlen(directory) + 1 +
5716 LUSTRE_VOLATILE_HDR_LEN,
5722 * Unlink file in case this wasn't a Lustre filesystem and the magic
5723 * volatile filename wasn't handled as intended. The effect is the
5724 * same. If volatile open was supported then we expect unlink() to
5727 (void)unlink(file_path);
5730 * Since we are returning successfully we restore errno (and
5731 * mask out possible EEXIST from open() and ENOENT from unlink().
5733 errno = saved_errno;
5739 * Create a file without any name open it for read/write
5741 * - file is created as if it were a standard file in the given \a directory
5742 * - file does not appear in \a directory and mtime does not change because
5743 * the filename is handled specially by the Lustre MDS.
5744 * - file is removed at final close
5745 * - file modes are rw------- since it doesn't make sense to have a read-only
5746 * or write-only file that cannot be opened again.
5747 * - if user wants another mode it must use fchmod() on the open file, no
5748 * security problems arise because it cannot be opened by another process.
5750 * \param[in] directory directory from which to inherit layout/MDT idx
5751 * \param[in] idx MDT index on which the file is created,
5752 * \a idx == -1 means no specific MDT is requested
5753 * \param[in] open_flags standard open(2) flags
5755 * \retval a file descriptor on success.
5756 * \retval -errno on error.
5758 int llapi_create_volatile_idx(const char *directory, int mdt_idx,
5761 return llapi_create_volatile_param(directory, mdt_idx, open_flags,
5762 S_IRUSR | S_IWUSR, NULL);
5766 * Swap the layouts between 2 file descriptors
5767 * the 2 files must be open for writing
5768 * first fd received the ioctl, second fd is passed as arg
5769 * this is assymetric but avoid use of root path for ioctl
5771 int llapi_fswap_layouts_grouplock(int fd1, int fd2, __u64 dv1, __u64 dv2,
5772 int gid, __u64 flags)
5774 struct lustre_swap_layouts lsl;
5779 if (flags & (SWAP_LAYOUTS_KEEP_ATIME | SWAP_LAYOUTS_KEEP_MTIME)) {
5780 rc = fstat(fd1, &st1);
5784 rc = fstat(fd2, &st2);
5789 lsl.sl_flags = flags;
5793 rc = ioctl(fd1, LL_IOC_LOV_SWAP_LAYOUTS, &lsl);
5797 if (flags & (SWAP_LAYOUTS_KEEP_ATIME | SWAP_LAYOUTS_KEEP_MTIME)) {
5798 struct timeval tv1[2];
5799 struct timeval tv2[2];
5801 memset(tv1, 0, sizeof(tv1));
5802 memset(tv2, 0, sizeof(tv2));
5804 if (flags & SWAP_LAYOUTS_KEEP_ATIME) {
5805 tv1[0].tv_sec = st1.st_atime;
5806 tv2[0].tv_sec = st2.st_atime;
5808 tv1[0].tv_sec = st2.st_atime;
5809 tv2[0].tv_sec = st1.st_atime;
5812 if (flags & SWAP_LAYOUTS_KEEP_MTIME) {
5813 tv1[1].tv_sec = st1.st_mtime;
5814 tv2[1].tv_sec = st2.st_mtime;
5816 tv1[1].tv_sec = st2.st_mtime;
5817 tv2[1].tv_sec = st1.st_mtime;
5820 rc = futimes(fd1, tv1);
5824 rc = futimes(fd2, tv2);
5832 int llapi_fswap_layouts(int fd1, int fd2, __u64 dv1, __u64 dv2, __u64 flags)
5839 while (grp_id == 0);
5841 rc = llapi_fswap_layouts_grouplock(fd1, fd2, dv1, dv2, grp_id, flags);
5849 * Swap the layouts between 2 files
5850 * the 2 files are open in write
5852 int llapi_swap_layouts(const char *path1, const char *path2,
5853 __u64 dv1, __u64 dv2, __u64 flags)
5857 fd1 = open(path1, O_WRONLY | O_LOV_DELAY_CREATE);
5860 llapi_error(LLAPI_MSG_ERROR, rc,
5861 "error: cannot open '%s' for write", path1);
5865 fd2 = open(path2, O_WRONLY | O_LOV_DELAY_CREATE);
5868 llapi_error(LLAPI_MSG_ERROR, rc,
5869 "error: cannot open '%s' for write", path2);
5873 rc = llapi_fswap_layouts(fd1, fd2, dv1, dv2, flags);
5875 llapi_error(LLAPI_MSG_ERROR, rc,
5876 "error: cannot swap layout between '%s' and '%s'",
5889 * \param fd File to lock.
5890 * \param gid Group Identifier.
5892 * \retval 0 on success.
5893 * \retval -errno on failure.
5895 int llapi_group_lock(int fd, int gid)
5899 rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
5902 llapi_error(LLAPI_MSG_ERROR, rc, "cannot get group lock");
5910 * \param fd File to unlock.
5911 * \param gid Group Identifier.
5913 * \retval 0 on success.
5914 * \retval -errno on failure.
5916 int llapi_group_unlock(int fd, int gid)
5920 rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
5923 llapi_error(LLAPI_MSG_ERROR, rc, "cannot put group lock");