-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
- */
-/*
- * Copyright (c) 2011 Whamcloud, Inc.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <liblustre.h>
#include <lnet/lnetctl.h>
#include <obd.h>
-#include <lustre_lib.h>
#include <obd_lov.h>
-#include <lustre/liblustreapi.h>
+#include <lustre/lustreapi.h>
static unsigned llapi_dir_filetype_table[] = {
[DT_UNKNOWN]= 0,
*size = strtoull(optarg, &end, 0);
if (*end != '\0') {
- if ((*end == 'b') && *(end+1) == '\0' &&
+ if ((*end == 'b') && *(end + 1) == '\0' &&
(*size & (~0ULL << (64 - 9))) == 0 &&
!bytes_spec) {
*size_units = 1 << 9;
- } else if ((*end == 'b') && *(end+1) == '\0' &&
+ } else if ((*end == 'b') &&
+ *(end + 1) == '\0' &&
bytes_spec) {
*size_units = 1;
} else if ((*end == 'k' || *end == 'K') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 10))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 10))) == 0) {
*size_units = 1 << 10;
} else if ((*end == 'm' || *end == 'M') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 20))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 20))) == 0) {
*size_units = 1 << 20;
} else if ((*end == 'g' || *end == 'G') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 30))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 30))) == 0) {
*size_units = 1 << 30;
} else if ((*end == 't' || *end == 'T') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 40))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 40))) == 0) {
*size_units = 1ULL << 40;
} else if ((*end == 'p' || *end == 'P') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 50))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 50))) == 0) {
*size_units = 1ULL << 50;
} else if ((*end == 'e' || *end == 'E') &&
- *(end+1) == '\0' && (*size &
- (~0ULL << (64 - 60))) == 0) {
+ *(end + 1) == '\0' &&
+ (*size & (~0ULL << (64 - 60))) == 0) {
*size_units = 1ULL << 60;
} else {
return -1;
/* XXX: llapi_xxx() functions return negative values upon failure */
int llapi_stripe_limit_check(unsigned long long stripe_size, int stripe_offset,
- int stripe_count, int stripe_pattern)
-{
- int page_size, rc;
-
- /* 64 KB is the largest common page size I'm aware of (on ia64), but
- * check the local page size just in case. */
- page_size = LOV_MIN_STRIPE_SIZE;
- if (getpagesize() > page_size) {
- page_size = getpagesize();
- llapi_err_noerrno(LLAPI_MSG_WARN,
- "warning: your page size (%u) is "
- "larger than expected (%u)", page_size,
- LOV_MIN_STRIPE_SIZE);
- }
- if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) {
- rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %lu, "
- "must be an even multiple of %d bytes",
- stripe_size, page_size);
- return rc;
- }
- if (stripe_offset < -1 || stripe_offset > MAX_OBD_DEVICES) {
- rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
- stripe_offset);
- return rc;
- }
- if (stripe_count < -1 || stripe_count > LOV_MAX_STRIPE_COUNT) {
- rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
- stripe_count);
- return rc;
- }
- if (stripe_size >= (1ULL << 32)){
- rc = -EINVAL;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "warning: stripe size larger than 4G "
- "is not currently supported and would wrap");
- return rc;
- }
- return 0;
+ int stripe_count, int stripe_pattern)
+{
+ int page_size, rc;
+
+ /* 64 KB is the largest common page size I'm aware of (on ia64), but
+ * check the local page size just in case. */
+ page_size = LOV_MIN_STRIPE_SIZE;
+ if (getpagesize() > page_size) {
+ page_size = getpagesize();
+ llapi_err_noerrno(LLAPI_MSG_WARN,
+ "warning: your page size (%u) is "
+ "larger than expected (%u)", page_size,
+ LOV_MIN_STRIPE_SIZE);
+ }
+ if (stripe_size < 0 || (stripe_size & (LOV_MIN_STRIPE_SIZE - 1))) {
+ rc = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe_size %lu, "
+ "must be an even multiple of %d bytes",
+ stripe_size, page_size);
+ return rc;
+ }
+ if (stripe_offset < -1 || stripe_offset > MAX_OBD_DEVICES) {
+ rc = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe offset %d",
+ stripe_offset);
+ return rc;
+ }
+ if (stripe_count < -1 || stripe_count > LOV_MAX_STRIPE_COUNT) {
+ rc = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: bad stripe count %d",
+ stripe_count);
+ return rc;
+ }
+ if (stripe_size >= (1ULL << 32)) {
+ rc = -EINVAL;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "warning: stripe size 4G or larger "
+ "is not currently supported and would wrap");
+ return rc;
+ }
+ return 0;
}
/* return the first file matching this pattern */
llapi_error(LLAPI_MSG_ERROR, rc,
"'%s' is not on a Lustre filesystem",
file_path);
+ if (fp != NULL)
+ fclose(fp);
return rc;
}
} else if (fsname) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
"Error reading pool list for '%s'", name);
- return rc;
+ goto out;
} else if ((rc == 0) && (cookie == NULL)) {
/* end of directory */
break;
continue;
/* check output bounds */
- if (nb_entries >= list_size)
- return -EOVERFLOW;
+ if (nb_entries >= list_size) {
+ rc = -EOVERFLOW;
+ goto out;
+ }
/* +2 for '.' and final '\0' */
- if (used + strlen(pool.d_name) + strlen(fsname) + 2
- > buffer_size)
- return -EOVERFLOW;
+ if (used + strlen(pool.d_name) + strlen(fsname) + 2
+ > buffer_size) {
+ rc = -EOVERFLOW;
+ goto out;
+ }
sprintf(buffer + used, "%s.%s", fsname, pool.d_name);
poollist[nb_entries] = buffer + used;
nb_entries++;
}
+out:
closedir(dir);
- return nb_entries;
+ return ((rc != 0) ? rc : nb_entries);
}
/* wrapper for lfs.c and obd.c */
return -ENOMEM;
}
- param->got_uuids = 0;
- param->obdindexes = NULL;
- param->obdindex = OBD_NOT_FOUND;
- return 0;
+ param->got_uuids = 0;
+ param->obdindexes = NULL;
+ param->obdindex = OBD_NOT_FOUND;
+ param->mdtindex = OBD_NOT_FOUND;
+ return 0;
}
static void find_param_fini(struct find_param *param)
if (ret == -EOVERFLOW) {
uuids_temp = realloc(uuids, obdcount *
sizeof(struct obd_uuid));
- if (uuids_temp != NULL)
+ if (uuids_temp != NULL) {
+ uuids = uuids_temp;
goto retry_get_uuids;
+ }
else
ret = -ENOMEM;
}
}
for (obdnum = 0; obdnum < num_obds; obdnum++) {
- for (i = 0; i < obdcount; i++) {
- if (llapi_uuid_match(uuids[i].uuid,
- obduuids[obdnum].uuid)) {
- indexes[obdnum] = i;
- obd_valid++;
- break;
+ char *end = NULL;
+
+ /* The user may have specified a simple index */
+ i = strtol(obduuids[obdnum].uuid, &end, 0);
+ if (end && *end == '\0' && i < obdcount) {
+ indexes[obdnum] = i;
+ obd_valid++;
+ } else {
+ for (i = 0; i < obdcount; i++) {
+ if (llapi_uuid_match(uuids[i].uuid,
+ obduuids[obdnum].uuid)) {
+ indexes[obdnum] = i;
+ obd_valid++;
+ break;
+ }
}
}
if (i >= obdcount) {
void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
struct lov_user_ost_data_v1 *objects,
- char *path, int is_dir,
- int obdindex, int depth, int header, int raw)
+ char *path, int is_dir, int obdindex,
+ int depth, int header, int raw)
{
int i, obdstripe = (obdindex != OBD_NOT_FOUND) ? 0 : 1;
* to be compared. */
if (param->obduuid || param->mdtuuid || param->check_uid ||
param->check_gid || param->check_pool || param->atime ||
- param->ctime || param->mtime || param->check_size)
+ param->ctime || param->mtime || param->check_size ||
+ param->check_stripecount || param->check_stripesize)
decision = 0;
if (param->type && checked_type == 0)
}
}
+ if (param->check_stripesize) {
+ decision = find_value_cmp(param->lmd->lmd_lmm.lmm_stripe_size,
+ param->stripesize,
+ param->stripesize_sign,
+ param->exclude_stripesize,
+ param->stripesize_units, 0);
+ if (decision == -1)
+ goto decided;
+ }
+
+ if (param->check_stripecount) {
+ decision = find_value_cmp(param->lmd->lmd_lmm.lmm_stripe_count,
+ param->stripecount,
+ param->stripecount_sign,
+ param->exclude_stripecount, 1, 0);
+ if (decision == -1)
+ goto decided;
+ }
+
+ /* If an OBD UUID is specified but none matches, skip this file. */
if ((param->obduuid && param->obdindex == OBD_NOT_FOUND) ||
(param->mdtuuid && param->mdtindex == OBD_NOT_FOUND))
goto decided;
return ret;
}
+ /* The 'LASSERT(parent != NULL || d != NULL);' guarantees
+ * that either 'd' or 'parent' is not null.
+ * So in all cases llapi_file_fget_mdtidx() is called,
+ * thus initializing 'mdtidx'. */
if (param->quiet || !(param->verbose & VERBOSE_DETAIL))
+ /* coverity[uninit_use_in_call] */
llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx);
else
- llapi_printf(LLAPI_MSG_NORMAL, "%s MDT index: %d\n",
+ /* coverity[uninit_use_in_call] */
+ llapi_printf(LLAPI_MSG_NORMAL, "%s\nmdt_index:\t%d\n",
path, mdtidx);
out:
}
dump:
- if (!param->get_mdt_index)
+ if (!(param->verbose & VERBOSE_MDTINDEX))
llapi_lov_dump_user_lmm(param, path, d ? 1 : 0);
out:
int llapi_getstripe(char *path, struct find_param *param)
{
- return param_callback(path, param->get_mdt_index ?
+ return param_callback(path, (param->verbose & VERBOSE_MDTINDEX) ?
cb_get_mdt_index : cb_getstripe,
cb_common_fini, param);
}
return rc;
}
+ /* The purpose is to send a byte as a ping, whatever this byte is. */
+ /* coverity[uninit_use_in_call] */
rc = write(fd, buf, 1);
if (rc < 0)
rc = -errno;
#undef MAX_STRING_SIZE
-int llapi_catinfo(char *dir, char *keyword, char *node_name)
-{
- char raw[OBD_MAX_IOCTL_BUFFER];
- char out[LLOG_CHUNK_SIZE];
- char *buf = raw;
- struct obd_ioctl_data data = { 0 };
- char key[30];
- DIR *root;
- int rc;
-
- sprintf(key, "%s", keyword);
- memset(raw, 0, sizeof(raw));
- memset(out, 0, sizeof(out));
- data.ioc_inlbuf1 = key;
- data.ioc_inllen1 = strlen(key) + 1;
- if (node_name) {
- data.ioc_inlbuf2 = node_name;
- data.ioc_inllen2 = strlen(node_name) + 1;
- }
- data.ioc_pbuf1 = out;
- data.ioc_plen1 = sizeof(out);
- rc = obd_ioctl_pack(&data, &buf, sizeof(raw));
- if (rc)
- return rc;
-
- root = opendir(dir);
- if (root == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", dir);
- return rc;
- }
-
- rc = ioctl(dirfd(root), OBD_IOC_LLOG_CATINFO, buf);
- if (rc) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "ioctl OBD_IOC_CATINFO failed");
- } else {
- llapi_printf(LLAPI_MSG_NORMAL, "%s", data.ioc_pbuf1);
- }
-
- closedir(root);
- return rc;
-}
-
/* Is this a lustre fs? */
int llapi_is_lustre_mnttype(const char *type)
{
{
FILE *fp;
struct mntent *mnt;
- int found = 0, fd, rc;
+ int found = 0, fd = 0, rc = 0;
fp = setmntent(MOUNTED, "r");
if (fp == NULL) {
if (!mnt)
break;
- if (!llapi_is_lustre_mnt(mnt))
+ if (!llapi_is_lustre_mnt(mnt))
continue;
fd = open(mnt->mnt_dir, O_RDONLY | O_DIRECTORY);
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
"Can't open '%s'\n", mnt->mnt_dir);
- return rc;
+ goto out;
}
rc = ioctl(fd, LL_IOC_RMTACL, ops);
+ close(fd);
if (rc < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "ioctl %d\n", fd);
- return rc;
+ goto out;
}
found++;
}
+
+out:
endmntent(fp);
- return found;
+ return ((rc != 0) ? rc : found);
}
static char *next_token(char *p, int div)
return 0;
}
+/** Convert a changelog_rec to changelog_ext_rec, in this way client can treat
+ * all records in the format of changelog_ext_rec, this can make record
+ * analysis simpler.
+ */
+static inline int changelog_extend_rec(struct changelog_ext_rec *ext)
+{
+ if (!CHANGELOG_REC_EXTENDED(ext)) {
+ struct changelog_rec *rec = (struct changelog_rec *)ext;
+
+ memmove(ext->cr_name, rec->cr_name, rec->cr_namelen);
+ fid_zero(&ext->cr_sfid);
+ fid_zero(&ext->cr_spfid);
+ return 1;
+ }
+
+ return 0;
+}
+
/** Read the next changelog entry
* @param priv Opaque private control structure
* @param rech Changelog record handle; record will be allocated here
* <0 error code
* 1 EOF
*/
-int llapi_changelog_recv(void *priv, struct changelog_rec **rech)
+int llapi_changelog_recv(void *priv, struct changelog_ext_rec **rech)
{
struct changelog_private *cp = (struct changelog_private *)priv;
struct kuc_hdr *kuch;
}
}
- /* Our message is a changelog_rec. Use pointer math to skip
- * kuch_hdr and point directly to the message payload.
- */
- *rech = (struct changelog_rec *)(kuch + 1);
+ /* Our message is a changelog_ext_rec. Use pointer math to skip
+ * kuch_hdr and point directly to the message payload.
+ */
+ *rech = (struct changelog_ext_rec *)(kuch + 1);
+ changelog_extend_rec(*rech);
return 0;
}
/** Release the changelog record when done with it. */
-int llapi_changelog_free(struct changelog_rec **rech)
+int llapi_changelog_free(struct changelog_ext_rec **rech)
{
if (*rech) {
/* We allocated memory starting at the kuc_hdr, but passed
memset(fid, 0, sizeof(*fid));
fd = open(path, O_RDONLY | O_NONBLOCK | O_NOFOLLOW);
if (fd < 0) {
- if (errno == ELOOP) /* symbolic link */
+ if (errno == ELOOP || errno == ENXIO)
return path2fid_from_lma(path, fid);
return -errno;
}
rc = ioctl(fd, LL_IOC_PATH2FID, fid) < 0 ? -errno : 0;
- if (rc == -EINVAL) /* char special device */
+ if (rc == -EINVAL || rc == -ENOTTY)
rc = path2fid_from_lma(path, fid);
close(fd);
/** Release the action list when done with it. */
int llapi_copytool_free(struct hsm_action_list **hal)
{
- /* Reuse the llapi_changelog_free function */
- return llapi_changelog_free((struct changelog_rec **)hal);
+ /* Reuse the llapi_changelog_free function */
+ return llapi_changelog_free((struct changelog_ext_rec **)hal);
}
int llapi_get_connect_flags(const char *mnt, __u64 *flags)
*version = data->ioc_bulk;
return 0;
}
+
+/**
+ * Get a 64-bit value representing the version of file data pointed by fd.
+ *
+ * Each write or truncate, flushed on OST, will change this value. You can use
+ * this value to verify if file data was modified. This only checks the file
+ * data, not metadata.
+ *
+ * \param flags If set to LL_DV_NOFLUSH, the data version will be read
+ * directly from OST without regard to possible dirty cache on
+ * client nodes.
+ *
+ * \retval 0 on success.
+ * \retval -errno on error.
+ */
+int llapi_get_data_version(int fd, __u64 *data_version, __u64 flags)
+{
+ int rc;
+ struct ioc_data_version idv;
+
+ idv.idv_flags = flags;
+
+ rc = ioctl(fd, LL_IOC_DATA_VERSION, &idv);
+ if (rc)
+ rc = -errno;
+ else
+ *data_version = idv.idv_version;
+
+ return rc;
+}