lu_ref.h \
lustre_acl.h \
lustre_barrier.h \
- lustre_cfg.h \
lustre_compat.h \
lustre_debug.h \
lustre_disk.h \
+++ /dev/null
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, 2014, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#ifndef _LUSTRE_CFG_H
-#define _LUSTRE_CFG_H
-
-#include <libcfs/libcfs.h>
-#include <lustre/lustre_user.h>
-
-#ifdef __KERNEL__
-# include <obd_support.h>
-#else /* !__KERNEL__ */
-# include <malloc.h>
-# include <stdlib.h>
-#endif /* __KERNEL__ */
-
-/** \defgroup cfg cfg
- *
- * @{
- */
-
-/*
- * 1cf6
- * lcfG
- */
-#define LUSTRE_CFG_VERSION 0x1cf60001
-#define LUSTRE_CFG_MAX_BUFCOUNT 8
-
-#define LCFG_HDR_SIZE(count) \
- cfs_size_round(offsetof (struct lustre_cfg, lcfg_buflens[(count)]))
-
-/** If the LCFG_REQUIRED bit is set in a configuration command,
- * then the client is required to understand this parameter
- * in order to mount the filesystem. If it does not understand
- * a REQUIRED command the client mount will fail. */
-#define LCFG_REQUIRED 0x0001000
-
-enum lcfg_command_type {
- LCFG_ATTACH = 0x00cf001, /**< create a new obd instance */
- LCFG_DETACH = 0x00cf002, /**< destroy obd instance */
- LCFG_SETUP = 0x00cf003, /**< call type-specific setup */
- LCFG_CLEANUP = 0x00cf004, /**< call type-specific cleanup */
- LCFG_ADD_UUID = 0x00cf005, /**< add a nid to a niduuid */
- LCFG_DEL_UUID = 0x00cf006, /**< remove a nid from a niduuid */
- LCFG_MOUNTOPT = 0x00cf007, /**< create a profile (mdc, osc) */
- LCFG_DEL_MOUNTOPT = 0x00cf008, /**< destroy a profile */
- LCFG_SET_TIMEOUT = 0x00cf009, /**< set obd_timeout */
- LCFG_SET_UPCALL = 0x00cf00a, /**< deprecated */
- LCFG_ADD_CONN = 0x00cf00b, /**< add a failover niduuid to an obd */
- LCFG_DEL_CONN = 0x00cf00c, /**< remove a failover niduuid */
- LCFG_LOV_ADD_OBD = 0x00cf00d, /**< add an osc to a lov */
- LCFG_LOV_DEL_OBD = 0x00cf00e, /**< remove an osc from a lov */
- LCFG_PARAM = 0x00cf00f, /**< set a proc parameter */
- LCFG_MARKER = 0x00cf010, /**< metadata about next cfg rec */
- LCFG_LOG_START = 0x00ce011, /**< mgc only, process a cfg log */
- LCFG_LOG_END = 0x00ce012, /**< stop processing updates */
- LCFG_LOV_ADD_INA = 0x00ce013, /**< like LOV_ADD_OBD, inactive */
- LCFG_ADD_MDC = 0x00cf014, /**< add an mdc to a lmv */
- LCFG_DEL_MDC = 0x00cf015, /**< remove an mdc from a lmv */
- LCFG_SPTLRPC_CONF = 0x00ce016, /**< security */
- LCFG_POOL_NEW = 0x00ce020, /**< create an ost pool name */
- LCFG_POOL_ADD = 0x00ce021, /**< add an ost to a pool */
- LCFG_POOL_REM = 0x00ce022, /**< remove an ost from a pool */
- LCFG_POOL_DEL = 0x00ce023, /**< destroy an ost pool name */
- LCFG_SET_LDLM_TIMEOUT = 0x00ce030, /**< set ldlm_timeout */
- LCFG_PRE_CLEANUP = 0x00cf031, /**< call type-specific pre
- * cleanup cleanup */
- LCFG_SET_PARAM = 0x00ce032, /**< use set_param syntax to set
- *a proc parameters */
- LCFG_NODEMAP_ADD = 0x00ce040, /**< create a cluster */
- LCFG_NODEMAP_DEL = 0x00ce041, /**< destroy a cluster */
- LCFG_NODEMAP_ADD_RANGE = 0x00ce042, /**< add a nid range */
- LCFG_NODEMAP_DEL_RANGE = 0x00ce043, /**< delete an nid range */
- LCFG_NODEMAP_ADD_UIDMAP = 0x00ce044, /**< add a uidmap */
- LCFG_NODEMAP_DEL_UIDMAP = 0x00ce045, /**< delete a uidmap */
- LCFG_NODEMAP_ADD_GIDMAP = 0x00ce046, /**< add a gidmap */
- LCFG_NODEMAP_DEL_GIDMAP = 0x00ce047, /**< delete a gidmap */
- LCFG_NODEMAP_ACTIVATE = 0x00ce048, /**< activate cluster id mapping */
- LCFG_NODEMAP_ADMIN = 0x00ce049, /**< allow cluster to use id 0 */
- LCFG_NODEMAP_TRUSTED = 0x00ce050, /**< trust a clusters ids */
- LCFG_NODEMAP_SQUASH_UID = 0x00ce051, /**< default map uid */
- LCFG_NODEMAP_SQUASH_GID = 0x00ce052, /**< default map gid */
- LCFG_NODEMAP_ADD_SHKEY = 0x00ce053, /**< add shared key to cluster */
- LCFG_NODEMAP_DEL_SHKEY = 0x00ce054, /**< delete shared key from cluster */
- LCFG_NODEMAP_TEST_NID = 0x00ce055, /**< test for nodemap membership */
- LCFG_NODEMAP_TEST_ID = 0x00ce056, /**< test uid/gid mapping */
- LCFG_NODEMAP_SET_FILESET = 0x00ce057, /**< set fileset */
- LCFG_NODEMAP_DENY_UNKNOWN = 0x00ce058, /**< deny squashed nodemap users */
- LCFG_NODEMAP_MAP_MODE = 0x00ce059, /**< set the mapping mode */
-};
-
-struct lustre_cfg_bufs {
- void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT];
- __u32 lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT];
- __u32 lcfg_bufcount;
-};
-
-struct lustre_cfg {
- __u32 lcfg_version;
- __u32 lcfg_command;
-
- __u32 lcfg_num;
- __u32 lcfg_flags;
- __u64 lcfg_nid;
- __u32 lcfg_nal; /* not used any more */
-
- __u32 lcfg_bufcount;
- __u32 lcfg_buflens[0];
-};
-
-enum cfg_record_type {
- PORTALS_CFG_TYPE = 1,
- LUSTRE_CFG_TYPE = 123,
-};
-
-#define LUSTRE_CFG_BUFLEN(lcfg, idx) \
- ((lcfg)->lcfg_bufcount <= (idx) \
- ? 0 \
- : (lcfg)->lcfg_buflens[(idx)])
-
-static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
- __u32 index,
- void *buf,
- __u32 buflen)
-{
- if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
- return;
- if (bufs == NULL)
- return;
-
- if (bufs->lcfg_bufcount <= index)
- bufs->lcfg_bufcount = index + 1;
-
- bufs->lcfg_buf[index] = buf;
- bufs->lcfg_buflen[index] = buflen;
-}
-
-static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
- __u32 index,
- char *str)
-{
- lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
-}
-
-static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name)
-{
- memset((bufs), 0, sizeof(*bufs));
- if (name)
- lustre_cfg_bufs_set_string(bufs, 0, name);
-}
-
-static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, __u32 index)
-{
- __u32 i;
- size_t offset;
- __u32 bufcount;
-
- if (!lcfg)
- return NULL;
-
- bufcount = lcfg->lcfg_bufcount;
- if (index >= bufcount)
- return NULL;
-
- offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
- for (i = 0; i < index; i++)
- offset += cfs_size_round(lcfg->lcfg_buflens[i]);
- return (char *)lcfg + offset;
-}
-
-static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
- struct lustre_cfg *lcfg)
-{
- __u32 i;
- bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
- for (i = 0; i < bufs->lcfg_bufcount; i++) {
- bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
- bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i);
- }
-}
-
-static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, __u32 index)
-{
- char *s;
-
- if (lcfg->lcfg_buflens[index] == 0)
- return NULL;
-
- s = lustre_cfg_buf(lcfg, index);
- if (s == NULL)
- return NULL;
-
- /*
- * make sure it's NULL terminated, even if this kills a char
- * of data. Try to use the padding first though.
- */
- if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
- size_t last = cfs_size_round(lcfg->lcfg_buflens[index]) - 1;
- char lost;
-
- /* Use the smaller value */
- if (last > lcfg->lcfg_buflens[index])
- last = lcfg->lcfg_buflens[index];
-
- lost = s[last];
- s[last] = '\0';
- if (lost != '\0') {
- CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
- index, s, lost);
- }
- }
- return s;
-}
-
-static inline __u32 lustre_cfg_len(__u32 bufcount, __u32 *buflens)
-{
- __u32 i;
- __u32 len;
- ENTRY;
-
- len = LCFG_HDR_SIZE(bufcount);
- for (i = 0; i < bufcount; i++)
- len += cfs_size_round(buflens[i]);
-
- RETURN(cfs_size_round(len));
-}
-
-static inline void lustre_cfg_init(struct lustre_cfg *lcfg, int cmd,
- struct lustre_cfg_bufs *bufs)
-{
- char *ptr;
- __u32 i;
-
- lcfg->lcfg_version = LUSTRE_CFG_VERSION;
- lcfg->lcfg_command = cmd;
- lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
-
- ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
- for (i = 0; i < lcfg->lcfg_bufcount; i++) {
- lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
- if (bufs->lcfg_buf[i]) {
- memcpy(ptr, bufs->lcfg_buf[i], bufs->lcfg_buflen[i]);
- ptr += cfs_size_round(bufs->lcfg_buflen[i]);
- }
- }
-}
-
-static inline struct lustre_cfg *lustre_cfg_new(int cmd,
- struct lustre_cfg_bufs *bufs)
-{
- struct lustre_cfg *lcfg;
-
-#ifdef __KERNEL__
- OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
-#else /* !__KERNEL__ */
- lcfg = malloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
-#endif /* __KERNEL__ */
-
- if (lcfg != NULL)
- lustre_cfg_init(lcfg, cmd, bufs);
-
- return lcfg;
-}
-
-static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
-{
-#ifdef __KERNEL__
- OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
-#else /* ! __KERNEL__ */
- free(lcfg);
-#endif /* __KERNEL__ */
-}
-
-static inline int lustre_cfg_sanity_check(void *buf, size_t len)
-{
- struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
- ENTRY;
- if (!lcfg)
- RETURN(-EINVAL);
-
- /* check that the first bits of the struct are valid */
- if (len < LCFG_HDR_SIZE(0))
- RETURN(-EINVAL);
-
- if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
- RETURN(-EINVAL);
-
- if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
- RETURN(-EINVAL);
-
- /* check that the buflens are valid */
- if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
- RETURN(-EINVAL);
-
- /* make sure all the pointers point inside the data */
- if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
- RETURN(-EINVAL);
-
- RETURN(0);
-}
-
-/** @} cfg */
-
-#endif /* _LUSTRE_CFG_H */
#include <libcfs/libcfs.h>
#include <lustre/lustre_idl.h>
#include <lustre_ver.h>
-#include <lustre_cfg.h>
+#include <uapi/linux/lustre_cfg.h>
/* target.c */
struct ptlrpc_request;
char *new_param;
};
+char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
const char *new_name);
int class_process_config(struct lustre_cfg *lcfg);
#
EXTRA_DIST = \
+ lustre_cfg.h \
lustre_disk.h \
lustre_fid.h \
lustre_ioctl.h \
--- /dev/null
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#ifndef _UAPI_LUSTRE_CFG_H
+#define _UAPI_LUSTRE_CFG_H
+
+#include <linux/kernel.h>
+#include <lustre/lustre_user.h>
+
+/* Handle older distros */
+#ifndef __ALIGN_KERNEL
+# define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
+# define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#endif
+
+/** \defgroup cfg cfg
+ *
+ * @{
+ */
+
+/*
+ * 1cf6
+ * lcfG
+ */
+#define LUSTRE_CFG_VERSION 0x1cf60001
+#define LUSTRE_CFG_MAX_BUFCOUNT 8
+
+#define LCFG_HDR_SIZE(count) \
+ __ALIGN_KERNEL(offsetof(struct lustre_cfg, lcfg_buflens[(count)]), 8)
+
+/** If the LCFG_REQUIRED bit is set in a configuration command,
+ * then the client is required to understand this parameter
+ * in order to mount the filesystem. If it does not understand
+ * a REQUIRED command the client mount will fail.
+ */
+#define LCFG_REQUIRED 0x0001000
+
+enum lcfg_command_type {
+ LCFG_ATTACH = 0x00cf001, /**< create a new obd instance */
+ LCFG_DETACH = 0x00cf002, /**< destroy obd instance */
+ LCFG_SETUP = 0x00cf003, /**< call type-specific setup */
+ LCFG_CLEANUP = 0x00cf004, /**< call type-specific cleanup
+ */
+ LCFG_ADD_UUID = 0x00cf005, /**< add a nid to a niduuid */
+ LCFG_DEL_UUID = 0x00cf006, /**< remove a nid from
+ * a niduuid
+ */
+ LCFG_MOUNTOPT = 0x00cf007, /**< create a profile
+ * (mdc, osc)
+ */
+ LCFG_DEL_MOUNTOPT = 0x00cf008, /**< destroy a profile */
+ LCFG_SET_TIMEOUT = 0x00cf009, /**< set obd_timeout */
+ LCFG_SET_UPCALL = 0x00cf00a, /**< deprecated */
+ LCFG_ADD_CONN = 0x00cf00b, /**< add a failover niduuid to
+ * an obd
+ */
+ LCFG_DEL_CONN = 0x00cf00c, /**< remove a failover niduuid */
+ LCFG_LOV_ADD_OBD = 0x00cf00d, /**< add an osc to a lov */
+ LCFG_LOV_DEL_OBD = 0x00cf00e, /**< remove an osc from a lov */
+ LCFG_PARAM = 0x00cf00f, /**< set a proc parameter */
+ LCFG_MARKER = 0x00cf010, /**< metadata about next
+ * cfg rec
+ */
+ LCFG_LOG_START = 0x00ce011, /**< mgc only, process a
+ * cfg log
+ */
+ LCFG_LOG_END = 0x00ce012, /**< stop processing updates */
+ LCFG_LOV_ADD_INA = 0x00ce013, /**< like LOV_ADD_OBD,
+ * inactive
+ */
+ LCFG_ADD_MDC = 0x00cf014, /**< add an mdc to a lmv */
+ LCFG_DEL_MDC = 0x00cf015, /**< remove an mdc from a lmv */
+ LCFG_SPTLRPC_CONF = 0x00ce016, /**< security */
+ LCFG_POOL_NEW = 0x00ce020, /**< create an ost pool name */
+ LCFG_POOL_ADD = 0x00ce021, /**< add an ost to a pool */
+ LCFG_POOL_REM = 0x00ce022, /**< remove an ost from a pool */
+ LCFG_POOL_DEL = 0x00ce023, /**< destroy an ost pool name */
+ LCFG_SET_LDLM_TIMEOUT = 0x00ce030, /**< set ldlm_timeout */
+ LCFG_PRE_CLEANUP = 0x00cf031, /**< call type-specific pre
+ * cleanup cleanup
+ */
+ LCFG_SET_PARAM = 0x00ce032, /**< use set_param syntax to set
+ * a proc parameters
+ */
+ LCFG_NODEMAP_ADD = 0x00ce040, /**< create a cluster */
+ LCFG_NODEMAP_DEL = 0x00ce041, /**< destroy a cluster */
+ LCFG_NODEMAP_ADD_RANGE = 0x00ce042, /**< add a nid range */
+ LCFG_NODEMAP_DEL_RANGE = 0x00ce043, /**< delete an nid range */
+ LCFG_NODEMAP_ADD_UIDMAP = 0x00ce044, /**< add a uidmap */
+ LCFG_NODEMAP_DEL_UIDMAP = 0x00ce045, /**< delete a uidmap */
+ LCFG_NODEMAP_ADD_GIDMAP = 0x00ce046, /**< add a gidmap */
+ LCFG_NODEMAP_DEL_GIDMAP = 0x00ce047, /**< delete a gidmap */
+ LCFG_NODEMAP_ACTIVATE = 0x00ce048, /**< activate cluster
+ * id mapping
+ */
+ LCFG_NODEMAP_ADMIN = 0x00ce049, /**< allow cluster to use id 0 */
+ LCFG_NODEMAP_TRUSTED = 0x00ce050, /**< trust a clusters ids */
+ LCFG_NODEMAP_SQUASH_UID = 0x00ce051, /**< default map uid */
+ LCFG_NODEMAP_SQUASH_GID = 0x00ce052, /**< default map gid */
+ LCFG_NODEMAP_ADD_SHKEY = 0x00ce053, /**< add shared key to cluster */
+ LCFG_NODEMAP_DEL_SHKEY = 0x00ce054, /**< delete shared key from
+ * cluster
+ */
+ LCFG_NODEMAP_TEST_NID = 0x00ce055, /**< test for nodemap
+ * membership
+ */
+ LCFG_NODEMAP_TEST_ID = 0x00ce056, /**< test uid/gid mapping */
+ LCFG_NODEMAP_SET_FILESET = 0x00ce057, /**< set fileset */
+ LCFG_NODEMAP_DENY_UNKNOWN = 0x00ce058, /**< deny squashed nodemap
+ * users
+ */
+ LCFG_NODEMAP_MAP_MODE = 0x00ce059, /**< set the mapping mode */
+};
+
+struct lustre_cfg_bufs {
+ void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT];
+ __u32 lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT];
+ __u32 lcfg_bufcount;
+};
+
+struct lustre_cfg {
+ __u32 lcfg_version;
+ __u32 lcfg_command;
+
+ __u32 lcfg_num;
+ __u32 lcfg_flags;
+ __u64 lcfg_nid;
+ __u32 lcfg_nal; /* not used any more */
+
+ __u32 lcfg_bufcount;
+ __u32 lcfg_buflens[0];
+};
+
+enum cfg_record_type {
+ PORTALS_CFG_TYPE = 1,
+ LUSTRE_CFG_TYPE = 123,
+};
+
+#define LUSTRE_CFG_BUFLEN(lcfg, idx) \
+ ((lcfg)->lcfg_bufcount <= (idx) ? 0 : (lcfg)->lcfg_buflens[(idx)])
+
+static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
+ __u32 index, void *buf, __u32 buflen)
+{
+ if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
+ return;
+
+ if (!bufs)
+ return;
+
+ if (bufs->lcfg_bufcount <= index)
+ bufs->lcfg_bufcount = index + 1;
+
+ bufs->lcfg_buf[index] = buf;
+ bufs->lcfg_buflen[index] = buflen;
+}
+
+static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
+ __u32 index, char *str)
+{
+ lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
+}
+
+static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs,
+ char *name)
+{
+ memset((bufs), 0, sizeof(*bufs));
+ if (name)
+ lustre_cfg_bufs_set_string(bufs, 0, name);
+}
+
+static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, __u32 index)
+{
+ __u32 i;
+ size_t offset;
+ __u32 bufcount;
+
+ if (!lcfg)
+ return NULL;
+
+ bufcount = lcfg->lcfg_bufcount;
+ if (index >= bufcount)
+ return NULL;
+
+ offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
+ for (i = 0; i < index; i++)
+ offset += __ALIGN_KERNEL(lcfg->lcfg_buflens[i], 8);
+ return (char *)lcfg + offset;
+}
+
+static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
+ struct lustre_cfg *lcfg)
+{
+ __u32 i;
+
+ bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
+ for (i = 0; i < bufs->lcfg_bufcount; i++) {
+ bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
+ bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i);
+ }
+}
+
+static inline __u32 lustre_cfg_len(__u32 bufcount, __u32 *buflens)
+{
+ __u32 i;
+ __u32 len;
+
+ len = LCFG_HDR_SIZE(bufcount);
+ for (i = 0; i < bufcount; i++)
+ len += __ALIGN_KERNEL(buflens[i], 8);
+
+ return __ALIGN_KERNEL(len, 8);
+}
+
+static inline void lustre_cfg_init(struct lustre_cfg *lcfg, int cmd,
+ struct lustre_cfg_bufs *bufs)
+{
+ char *ptr;
+ __u32 i;
+
+ lcfg->lcfg_version = LUSTRE_CFG_VERSION;
+ lcfg->lcfg_command = cmd;
+ lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
+
+ ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
+ for (i = 0; i < lcfg->lcfg_bufcount; i++) {
+ lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
+ if (bufs->lcfg_buf[i]) {
+ memcpy(ptr, bufs->lcfg_buf[i], bufs->lcfg_buflen[i]);
+ ptr += __ALIGN_KERNEL(bufs->lcfg_buflen[i], 8);
+ }
+ }
+}
+
+static inline int lustre_cfg_sanity_check(void *buf, size_t len)
+{
+ struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
+
+ if (!lcfg)
+ return -EINVAL;
+
+ /* check that the first bits of the struct are valid */
+ if (len < LCFG_HDR_SIZE(0))
+ return -EINVAL;
+
+ if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
+ return -EINVAL;
+
+ if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
+ return -EINVAL;
+
+ /* check that the buflens are valid */
+ if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
+ return -EINVAL;
+
+ /* make sure all the pointers point inside the data */
+ if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
+ return -EINVAL;
+
+ return 0;
+}
+
+/** @} cfg */
+
+#endif /* _UAPI_LUSTRE_CFG_H */
#define _LOD_INTERNAL_H
#include <libcfs/libcfs.h>
-#include <lustre_cfg.h>
+#include <uapi/linux/lustre_cfg.h>
#include <obd.h>
#include <dt_object.h>
lustre_cfg_bufs_reset(&bufs, NULL);
snprintf(str, 32, "%smaxage=%u", PARAM_OSP, (__u32)val);
lustre_cfg_bufs_set_string(&bufs, 1, str);
- lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL)
return -ENOMEM;
+ lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
lod_getref(&lod->lod_ost_descs);
lod_foreach_ost(lod, i) {
CERROR("can't set maxage on #%d: %d\n", i, rc);
}
lod_putref(lod, &lod->lod_ost_descs);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
return count;
}
* by osd only doesn't have mdt/mdd slices -bzzz */
lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
lustre_cfg_bufs_set_string(bufs, 1, NULL);
- lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
RETURN_EXIT;
+ lustre_cfg_init(lcfg, LCFG_PRE_CLEANUP, bufs);
top->ld_ops->ldo_process_config(env, top, lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
EXIT;
}
if (obd->obd_fail)
strcat(flags, "A");
lustre_cfg_bufs_set_string(bufs, 1, flags);
- lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
RETURN_EXIT;
+ lustre_cfg_init(lcfg, LCFG_CLEANUP, bufs);
LASSERT(top);
top->ld_ops->ldo_process_config(env, top, lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
lu_site_purge(env, top->ld_site, -1);
lustre_cfg_bufs_set_string(bufs, 2, uuid);
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
- lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(put_profile, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_ATTACH, bufs);
rc = class_attach(lcfg);
if (rc)
GOTO(lcfg_cleanup, rc = -EINVAL);
}
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
lustre_cfg_bufs_reset(bufs, name);
lustre_cfg_bufs_set_string(bufs, 1, uuid);
lustre_cfg_bufs_set_string(bufs, 2, dev);
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
- lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(class_detach, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_SETUP, bufs);
rc = class_setup(obd, lcfg);
if (rc)
if (rc)
class_detach(obd, lcfg);
lcfg_cleanup:
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
put_profile:
class_put_profile(lprof);
free_bufs:
lustre_cfg_bufs_set_string(bufs, 2, uuid);
lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
- lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(put_profile, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_ATTACH, bufs);
rc = class_attach(lcfg);
if (rc)
GOTO(lcfg_cleanup, rc = -EINVAL);
}
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
lustre_cfg_bufs_reset(bufs, qmtname);
lustre_cfg_bufs_set_string(bufs, 1, uuid);
lustre_cfg_bufs_set_string(bufs, 3,
mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
- lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(class_detach, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_SETUP, bufs);
rc = class_setup(obd, lcfg);
if (rc)
if (rc)
class_detach(obd, lcfg);
lcfg_cleanup:
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
put_profile:
class_put_profile(lprof);
cleanup_mem:
cfg);
}
- if (old_cfg != NULL)
- lustre_cfg_free(cfg);
-
+ if (old_cfg)
+ OBD_FREE(cfg, lustre_cfg_len(cfg->lcfg_bufcount,
+ cfg->lcfg_buflens));
break;
}
default:
lustre_cfg_bufs_set_string(&bufs, 1, params);
- lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
- if (lcfg == NULL) {
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount,
+ bufs.lcfg_buflen));
+ if (!lcfg) {
rc = -ENOMEM;
break;
}
+ lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
CDEBUG(D_INFO, "ir apply logs %lld/%lld for %s -> %s\n",
prev_version, max_version, obdname, params);
rc = class_process_config(lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+ lcfg->lcfg_buflens));
if (rc)
CDEBUG(D_INFO, "process config for %s error %d\n",
obdname, rc);
/* Construct lustre_cfg structure to pass to function mgs_setparam */
lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL);
lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param);
- lcfg = lustre_cfg_new(LCFG_PARAM, &mgi->mgi_bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(mgi->mgi_bufs.lcfg_bufcount,
+ mgi->mgi_bufs.lcfg_buflen));
+ if (!lcfg)
RETURN(-ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_PARAM, &mgi->mgi_bufs);
rc = mgs_setparam(tsi->tsi_env, exp2mgs_dev(tsi->tsi_exp), lcfg,
mgi->mgi_fsname);
*rep_msp = *msp;
EXIT;
out_cfg:
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
return rc;
}
#endif
return rc;
}
+char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
+{
+ char *s;
+
+ if (!lcfg->lcfg_buflens[index])
+ return NULL;
+
+ s = lustre_cfg_buf(lcfg, index);
+ if (!s)
+ return NULL;
+
+ /*
+ * make sure it's NULL terminated, even if this kills a char
+ * of data. Try to use the padding first though.
+ */
+ if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
+ size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
+ char lost;
+
+ /* Use the smaller value */
+ if (last > lcfg->lcfg_buflens[index])
+ last = lcfg->lcfg_buflens[index];
+
+ lost = s[last];
+ s[last] = '\0';
+ if (lost != '\0') {
+ CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
+ index, s, lost);
+ }
+ }
+ return s;
+}
+EXPORT_SYMBOL(lustre_cfg_string);
+
/********************** class fns **********************/
/**
int new_len = 0;
ENTRY;
- if (cfg == NULL || new_name == NULL)
- RETURN(ERR_PTR(-EINVAL));
+ if (!cfg || !new_name)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
param = lustre_cfg_string(cfg, 1);
- if (param == NULL)
- RETURN(ERR_PTR(-EINVAL));
+ if (!param)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
value = strchr(param, '=');
if (value == NULL)
new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
OBD_ALLOC(new_param, new_len);
- if (new_param == NULL)
- RETURN(ERR_PTR(-ENOMEM));
+ if (!new_param)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
strcpy(new_param, new_name);
if (value != NULL)
strcat(new_param, value);
OBD_ALLOC_PTR(bufs);
- if (bufs == NULL) {
- OBD_FREE(new_param, new_len);
- RETURN(ERR_PTR(-ENOMEM));
- }
+ if (!bufs)
+ GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
lustre_cfg_bufs_reset(bufs, NULL);
lustre_cfg_bufs_init(bufs, cfg);
lustre_cfg_bufs_set_string(bufs, 1, new_param);
- new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);
- OBD_FREE(new_param, new_len);
- OBD_FREE_PTR(bufs);
- if (new_cfg == NULL)
- RETURN(ERR_PTR(-ENOMEM));
+ OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
+ bufs->lcfg_buflen));
+ if (!new_cfg)
+ GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
+
+ lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
new_cfg->lcfg_num = cfg->lcfg_num;
new_cfg->lcfg_flags = cfg->lcfg_flags;
new_cfg->lcfg_nid = cfg->lcfg_nid;
new_cfg->lcfg_nal = cfg->lcfg_nal;
-
+out_free_buf:
+ OBD_FREE_PTR(bufs);
+out_free_param:
+ OBD_FREE(new_param, new_len);
+out_nocfg:
RETURN(new_cfg);
}
EXPORT_SYMBOL(lustre_cfg_rename);
struct lustre_cfg_bufs bufs;
char *inst_name = NULL;
int inst_len = 0;
- int inst = 0, swab = 0;
+ int swab = 0;
lcfg = (struct lustre_cfg *)cfg_buf;
if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
if (cfg->cfg_instance &&
LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
- inst = 1;
inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
sizeof(cfg->cfg_instance) * 2 + 4;
OBD_ALLOC(inst_name, inst_len);
}
}
- lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
- if (lcfg_new == NULL)
+ OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
+ bufs.lcfg_buflen));
+ if (!lcfg_new)
GOTO(out, rc = -ENOMEM);
+ lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
lcfg_new->lcfg_num = lcfg->lcfg_num;
lcfg_new->lcfg_flags = lcfg->lcfg_flags;
lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
rc = class_process_config(lcfg_new);
- lustre_cfg_free(lcfg_new);
-
- if (inst)
+ OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
+ lcfg_new->lcfg_buflens));
+ if (inst_name)
OBD_FREE(inst_name, inst_len);
break;
}
lustre_cfg_bufs_reset(&bufs, obd->obd_name);
lustre_cfg_bufs_set_string(&bufs, 1, flags);
- lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+ if (!lcfg)
RETURN(-ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
rc = class_process_config(lcfg);
if (rc) {
if (rc)
CERROR("detach failed %d: %s\n", rc, obd->obd_name);
out:
- lustre_cfg_free(lcfg);
- RETURN(rc);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
+ RETURN(rc);
}
EXPORT_SYMBOL(class_manual_cleanup);
if (bufs == NULL)
RETURN(-ENOMEM);
- /* mgc_process_config */
- lustre_cfg_bufs_reset(bufs, mgc->obd_name);
- lustre_cfg_bufs_set_string(bufs, 1, logname);
- lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
- lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
- lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
- if (lcfg == NULL)
+ /* mgc_process_config */
+ lustre_cfg_bufs_reset(bufs, mgc->obd_name);
+ lustre_cfg_bufs_set_string(bufs, 1, logname);
+ lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
+ lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(out, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_LOG_START, bufs);
+
rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
out:
OBD_FREE_PTR(bufs);
RETURN(-ENOENT);
/* mgc_process_config */
- lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
- lustre_cfg_bufs_set_string(&bufs, 1, logname);
- if (cfg)
- lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
- lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
- if (lcfg == NULL)
+ lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
+ lustre_cfg_bufs_set_string(&bufs, 1, logname);
+ if (cfg)
+ lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+ if (!lcfg)
RETURN(-ENOMEM);
- rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
- lustre_cfg_free(lcfg);
- RETURN(rc);
+ lustre_cfg_init(lcfg, LCFG_LOG_END, &bufs);
+ rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
+ RETURN(rc);
}
EXPORT_SYMBOL(lustre_end_log);
if (s4)
lustre_cfg_bufs_set_string(&bufs, 4, s4);
- lcfg = lustre_cfg_new(cmd, &bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+ if (!lcfg)
return -ENOMEM;
- lcfg->lcfg_nid = nid;
- rc = class_process_config(lcfg);
- lustre_cfg_free(lcfg);
- return(rc);
+ lustre_cfg_init(lcfg, cmd, &bufs);
+ lcfg->lcfg_nid = nid;
+ rc = class_process_config(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
+ return rc;
}
/** Call class_attach and class_setup. These methods in turn call
lustre_cfg_bufs_set_string(bufs, 1,
lustre_cfg_string(cfg, 1));
- lcfg = lustre_cfg_new(LCFG_ADD_CONN, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(out_cfg, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_ADD_CONN, bufs);
+
rc = class_add_conn(lwp, lcfg);
if (rc)
CERROR("%s: can't add conn: rc = %d\n", lwpname, rc);
- if (lcfg != NULL)
- lustre_cfg_free(lcfg);
+ if (lcfg)
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+ lcfg->lcfg_buflens));
out_cfg:
if (bufs != NULL)
OBD_FREE_PTR(bufs);
lustre_cfg_bufs_reset(bufs, lwp->obd_name);
lustre_cfg_bufs_set_string(bufs, 1, NULL);
- lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
+ bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(out, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_CLEANUP, bufs);
/* Disconnect import first. NULL is passed for the '@env',
* since it will not be used. */
rc = lwp->obd_lu_dev->ld_ops->ldo_process_config(NULL,
lwp->obd_lu_dev, lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+ lcfg->lcfg_buflens));
if (rc != 0 && rc != -ETIMEDOUT) {
CERROR("%s: fail to disconnect LWP: rc = %d\n",
lwp->obd_name, rc);
if (obd->obd_fail)
strcat(flags, "A");
lustre_cfg_bufs_set_string(&bufs, 1, flags);
- lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+ if (!lcfg)
RETURN_EXIT;
+ lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
LASSERT(top);
top->ld_ops->ldo_process_config(env, top, lcfg);
- lustre_cfg_free(lcfg);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
lu_site_purge(env, top->ld_site, ~0);
if (!cfs_hash_is_empty(top->ld_site->ls_obj_hash)) {
lustre_cfg_bufs_reset(bufs, lwp_name);
lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
lustre_cfg_bufs_set_string(bufs, 2, nidstring);
- lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (!lcfg)
GOTO(out, rc = -ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_SETUP, bufs);
rc = client_obd_setup(lwp->lpd_obd, lcfg);
if (rc != 0) {
OBD_FREE_PTR(bufs);
if (server_uuid != NULL)
OBD_FREE(server_uuid, len);
- if (lcfg != NULL)
- lustre_cfg_free(lcfg);
+ if (lcfg)
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+ lcfg->lcfg_buflens));
if (rc)
client_obd_cleanup(lwp->lpd_obd);
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/lustre_ostid.h>
#include <lustre/lustreapi.h>
#include <lustre_log_user.h>
-#include <lustre_cfg.h>
+#include <linux/lustre_cfg.h>
static inline int ext2_test_bit(int nr, const void *addr)
{
return;
}
+static char *lustre_cfg_string(struct lustre_cfg *lcfg, __u32 index)
+{
+ char *s;
+
+ if (lcfg->lcfg_buflens[index] == 0)
+ return NULL;
+
+ s = lustre_cfg_buf(lcfg, index);
+ if (s == NULL)
+ return NULL;
+
+ /*
+ * make sure it's NULL terminated, even if this kills a char
+ * of data. Try to use the padding first though.
+ */
+ if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
+ size_t last = __ALIGN_KERNEL(lcfg->lcfg_buflens[index], 8) - 1;
+ char lost;
+
+ /* Use the smaller value */
+ if (last > lcfg->lcfg_buflens[index])
+ last = lcfg->lcfg_buflens[index];
+
+ lost = s[last];
+ s[last] = '\0';
+ if (lost != '\0') {
+ fprintf(stderr, "Truncated buf %d to '%s' (lost '%c'...)\n",
+ index, s, lost);
+ }
+ }
+ return s;
+}
static void print_setup_cfg(struct lustre_cfg *lcfg)
{
#include <libcfs/util/param.h>
#include <libcfs/util/parser.h>
#include <lnet/nidstr.h>
-#include <lustre_cfg.h>
+#include <linux/lustre_cfg.h>
#include <linux/lustre_ioctl.h>
#include <lustre_ver.h>
return jt_obd_device(argc, argv);
}
+static int jt_lcfg_ioctl(struct lustre_cfg_bufs *bufs, char *arg, int cmd)
+{
+ struct lustre_cfg *lcfg;
+ int rc;
+
+ lcfg = malloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
+ if (lcfg == NULL) {
+ rc = -ENOMEM;
+ } else {
+ lustre_cfg_init(lcfg, cmd, bufs);
+ rc = lcfg_ioctl(arg, OBD_DEV_ID, lcfg);
+ free(lcfg);
+ }
+ if (rc < 0)
+ fprintf(stderr, "error: %s: %s\n", jt_cmdname(arg),
+ strerror(rc = errno));
+ return rc;
+}
+
int jt_lcfg_attach(int argc, char **argv)
{
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
int rc;
if (argc != 4)
lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
- lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0) {
- fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
- jt_cmdname(argv[0]), strerror(rc = errno));
- } else {
- lcfg_set_devname(argv[2]);
- }
+ rc = jt_lcfg_ioctl(&bufs, argv[0], LCFG_ATTACH);
+ if (rc == 0)
+ lcfg_set_devname(argv[2]);
- return rc;
+ return rc;
}
int jt_lcfg_setup(int argc, char **argv)
{
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
int i;
- int rc;
if (lcfg_devname == NULL) {
fprintf(stderr, "%s: please use 'device name' to set the "
lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
}
- lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0)
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
-
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_SETUP);
}
int jt_obd_detach(int argc, char **argv)
{
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
- int rc;
if (lcfg_devname == NULL) {
fprintf(stderr, "%s: please use 'device name' to set the "
if (argc != 1)
return CMD_HELP;
- lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0)
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
-
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_DETACH);
}
int jt_obd_cleanup(int argc, char **argv)
{
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
char force = 'F';
char failover = 'A';
char flags[3] = { 0 };
int flag_cnt = 0, n;
- int rc;
if (lcfg_devname == NULL) {
fprintf(stderr, "%s: please use 'device name' to set the "
lustre_cfg_bufs_set_string(&bufs, 1, flags);
}
- lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0)
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
-
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_CLEANUP);
}
static
-int do_add_uuid(char * func, char *uuid, lnet_nid_t nid)
+int do_add_uuid(char *func, char *uuid, lnet_nid_t nid)
{
int rc;
struct lustre_cfg_bufs bufs;
if (uuid != NULL)
lustre_cfg_bufs_set_string(&bufs, 1, uuid);
- lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL) {
rc = -ENOMEM;
} else {
+ lustre_cfg_init(lcfg, LCFG_ADD_UUID, &bufs);
lcfg->lcfg_nid = nid;
rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
+ free(lcfg);
}
if (rc) {
fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
int jt_lcfg_del_uuid(int argc, char **argv)
{
- int rc;
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
if (argc != 2) {
fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
if (strcmp (argv[1], "_all_"))
lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
- lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc) {
- fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
- strerror(errno));
- return -1;
- }
- return 0;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_DEL_UUID);
}
int jt_lcfg_del_mount_option(int argc, char **argv)
{
- int rc;
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
if (argc != 2)
return CMD_HELP;
/* profile name */
lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
- lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0) {
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
- }
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_DEL_MOUNTOPT);
}
int jt_lcfg_set_timeout(int argc, char **argv)
return CMD_HELP;
lustre_cfg_bufs_reset(&bufs, lcfg_devname);
- lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
+
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL) {
rc = -ENOMEM;
} else {
+ lustre_cfg_init(lcfg, LCFG_SET_TIMEOUT, &bufs);
lcfg->lcfg_num = atoi(argv[1]);
rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
+ free(lcfg);
}
if (rc < 0) {
fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
- lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL) {
rc = -ENOMEM;
} else {
+ lustre_cfg_init(lcfg, LCFG_ADD_CONN, &bufs);
lcfg->lcfg_num = priority;
rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
+ free(lcfg);
}
if (rc < 0) {
fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
int jt_lcfg_del_conn(int argc, char **argv)
{
struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
- int rc;
if (argc != 2)
return CMD_HELP;
/* connection uuid */
lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
- lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0) {
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
- }
-
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_DEL_MOUNTOPT);
}
/* Param set locally, directly on target */
int jt_lcfg_param(int argc, char **argv)
{
- int i, rc;
- struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
+ struct lustre_cfg_bufs bufs;
+ int i;
if (argc >= LUSTRE_CFG_MAX_BUFCOUNT)
return CMD_HELP;
lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
}
- lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
- if (lcfg == NULL) {
- rc = -ENOMEM;
- } else {
- rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
- lustre_cfg_free(lcfg);
- }
- if (rc < 0) {
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
- }
- return rc;
+ return jt_lcfg_ioctl(&bufs, argv[0], LCFG_PARAM);
}
struct param_opts {
}
lustre_cfg_bufs_set_string(&bufs, 1, buf);
- lcfg = lustre_cfg_new(LCFG_SET_PARAM, &bufs);
+
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount,
+ bufs.lcfg_buflen));
if (lcfg == NULL) {
fprintf(stderr, "error: allocating lcfg for %s: %s\n",
jt_cmdname(argv[0]), strerror(-ENOMEM));
if (rc == 0)
rc = -ENOMEM;
} else {
- int rc2 = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
+ int rc2;
+
+ lustre_cfg_init(lcfg, LCFG_SET_PARAM, &bufs);
+ rc2 = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
if (rc2 != 0) {
fprintf(stderr, "error: executing %s: %s\n",
jt_cmdname(argv[0]), strerror(errno));
if (rc == 0)
rc = rc2;
}
- lustre_cfg_free(lcfg);
+ free(lcfg);
}
if (buf != argv[i])
free(buf);
lustre_cfg_bufs_set_string(&bufs, 1, argv[optind]);
}
- /* We could put other opcodes here. */
- lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+ /* We could put other opcodes here. */
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL) {
rc = -ENOMEM;
} else {
+ lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
if (rc < 0)
rc = -errno;
- lustre_cfg_free(lcfg);
+ free(lcfg);
}
if (buf)
free(buf);
#include <dirent.h>
#include <dlfcn.h>
#include <lustre/lustre_idl.h>
-#include <lustre_cfg.h>
+#include <linux/lustre_cfg.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/xattr.h>
#include <lnet/nidstr.h>
#include <linux/lustre_ostid.h>
-#include <lustre_cfg.h>
+#include <linux/lustre_cfg.h>
#include <linux/lustre_ioctl.h>
#include <lustre_ver.h>
if (ostname != NULL)
lustre_cfg_bufs_set_string(&bufs, 2, ostname);
- lcfg = lustre_cfg_new(cmd, &bufs);
+
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL)
return -ENOMEM;
+ lustre_cfg_init(lcfg, cmd, &bufs);
memset(&data, 0, sizeof(data));
rc = data.ioc_dev = get_mgs_device();
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(cmdname));
- lustre_cfg_free(lcfg);
+ free(lcfg);
return rc;
}
rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);
out:
if (rc)
rc = -errno;
- lustre_cfg_free(lcfg);
+ free(lcfg);
return rc;
}
}
va_end(ap);
- lcfg = lustre_cfg_new(cmd, &bufs);
+ lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
if (lcfg == NULL)
return -ENOMEM;
+ lustre_cfg_init(lcfg, cmd, &bufs);
memset(&data, 0, sizeof(data));
rc = data.ioc_dev = get_mgs_device();
memcpy(ret_data, data.ioc_pbuf1, ret_size);
}
out:
- lustre_cfg_free(lcfg);
+ free(lcfg);
return rc;
}