#define IOC_LIBCFS_TYPE ('e')
#define IOC_LIBCFS_MIN_NR 30
/* libcfs ioctls */
-/* IOC_LIBCFS_PANIC obsolete in 2.8.0, was _IOWR('e', 30, IOCTL_LIBCFS_TYPE) */
+/* XXX: all of these ioctl definitions are broken, the first parameter
+ * should be IOCTL_LIBCFS_TYPE and the last parameter is the struct size.
+ */
#define IOC_LIBCFS_CLEAR_DEBUG _IOWR('e', 31, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_MARK_DEBUG _IOWR('e', 32, IOCTL_LIBCFS_TYPE)
-/* IOC_LIBCFS_MEMHOG obsolete in 2.8.0, was _IOWR('e', 36, IOCTL_LIBCFS_TYPE) */
/* lnet ioctls */
#define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_FAIL_NID _IOWR('e', 51, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_NOTIFY_ROUTER _IOWR('e', 55, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_UNCONFIGURE _IOWR('e', 56, IOCTL_LIBCFS_TYPE)
-/* IOC_LIBCFS_PORTALS_COMPATIBILITY _IOWR('e', 57, IOCTL_LIBCFS_TYPE) */
#define IOC_LIBCFS_LNET_DIST _IOWR('e', 58, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_CONFIGURE _IOWR('e', 59, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_TESTPROTOCOMPAT _IOWR('e', 60, IOCTL_LIBCFS_TYPE)
-/* IOC_LIBCFS_PING obsolete in 2.16, was _IOWR('e', 61, IOCTL_LIBCFS_TYPE) */
#define IOC_LIBCFS_PING_PEER _IOWR('e', 62, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_LNETST _IOWR('e', 63, IOCTL_LIBCFS_TYPE)
#define IOC_LIBCFS_LNET_FAULT _IOWR('e', 64, IOCTL_LIBCFS_TYPE)
llapi_hsm_copytool_unregister.3 \
llapi_hsm_state_get.3 \
llapi_hsm_state_set.3 \
+ llapi_ioctl.3 \
llapi_ladvise.3 \
llapi_layout.7 \
llapi_layout_alloc.3 \
--- /dev/null
+.TH lustreapi 3 "2023 Mar 22" Lustre user application interface library
+.SH NAME
+llapi_ioctl \- call ioctl() with possible command remapping
+.SH SYNOPSIS
+.nf
+.B #include <lustre/lustreapi.h>
+.sp
+.BI "int llapi_ioctl(int " fd ", unsigned int " cmd ", void *" buf ");"
+.SH DESCRIPTION
+.LP
+.B llapi_ioctl()
+calls the
+.BR ioctl (2)
+system call with the supplied arguments. However, if the ioctl() returns
+.B ENOTTY
+(no such ioctl) then if
+.I cmd
+has been remapped from an older ioctl command number the ioctl() call will
+be retried with the old ioctl command number.
+.SH RETURN VALUES
+.LP
+.B llapi_ioctl()
+typically returns:
+.TP
+0
+on success in most cases
+.TP
+<0
+a negative value on failure and sets
+.BR errno .
+Due to the variety of ioctl commands, it may return different values
+and errno as appropriate for the
+.IR fd ,
+.I cmd
+number, and argument
+.I buf
+passed.
+.SH "EXAMPLE"
+.nf
+#include <lustre/lustreapi.h>
+
+int main(int argc, char *argv[])
+{
+ unsigned long group = 1234;
+ int rc, fd;
+
+ fd = open(argv[1], O_RDONLY);
+ if (rc < 0) {
+ fprintf(stderr, "error opening file '%s': %s\\n",
+ argv[1], strerror(errno));
+ return -1;
+ }
+
+ rc = llapi_ioctl(fd, LL_IOC_GROUP_LOCK, &group);
+ if (rc < 0) {
+ fprintf(stderr, "%s: ioctl error: %s\\n",
+ argv[1], strerror(errno));
+ return rc;
+ }
+
+ printf("%s: locked with group %lu\\n", argv[1], group);
+ return 0;
+}
+.fi
+.SH "SEE ALSO"
+.BR lustre (7),
+.BR ioctl (2),
+.BR lustreapi (7)
+
lustre_idmap.h \
lustre_import.h \
lustre_intent.h \
+ lustre_ioctl_old.h \
lustre_lfsck.h \
lustre_lib.h \
lustre_linkea.h \
int llapi_heat_get(int fd, struct lu_heat *heat);
int llapi_heat_set(int fd, __u64 flags);
+int llapi_ioctl(int fd, unsigned int cmd, void *buf);
+
int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr);
void llapi_layout_sanity_perror(int error);
int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size);
--- /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
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ *
+ * Compatibility for deprecated ioctls that should no longer be used by tools.
+ *
+ * Copyright (c) 2023, DataDirect Networks Storage, all rights reserved.
+ */
+#ifndef __LUSTRE_IOCTL_OLD_H
+#define __LUSTRE_IOCTL_OLD_H
+
+#include <linux/lnet/libcfs_ioctl.h> /* for IOCTL_LIBCFS_TYPE */
+
+/* ioctl command is deprecated after release v1.v2 */
+#define case_OBD_IOC_DEPRECATED(cmd, dev, v1, v2) \
+ case cmd: \
+ if (LUSTRE_VERSION_CODE > OBD_OCD_VERSION(v1, v2, 53, 0)) { \
+ static bool printed; \
+ obd_ioctl_msg(__FILE__, __func__, __LINE__, \
+ printed ? D_IOCTL : D_WARNING, dev, cmd, \
+ "deprecated " #cmd " usage", 0); \
+ printed = true; \
+ }
+
+#define case_OBD_IOC_DEPRECATED_FT(cmd, dev, v1, v2) \
+ case_OBD_IOC_DEPRECATED(cmd, dev, v1, v2) \
+ fallthrough
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 19, 53, 0)
+#define OBD_GET_VERSION _IOWR('f', 144, OBD_IOC_DATA_TYPE) /*< 2.8.55 */
+#endif
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 99, 53, 0)
+/* for binary compatibility until 3.0, no more compiling into tools */
+#define OBD_IOC_GETNAME_OLD _IOWR('f', 131, OBD_IOC_DATA_TYPE) /*< 2.14.52*/
+
+#define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE) /*< 2.15.53*/
+#define IOC_LIBCFS_PING _IOWR('e', 61, IOCTL_LIBCFS_TYPE) /*< 2.15.53*/
+
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 19, 53, 0)
+#define OBD_IOC_BARRIER _IOWR('g', 5, OBD_IOC_DATA_TYPE) /*< 2.16.55*/
+#define IOC_OSC_SET_ACTIVE _IOWR('h', 21, void *) /*< 2.16.55*/
+#endif
+
+#endif /* OBD_OCD_VERSION(2, 99, 53, 0) */
+
+/* We don't need *_ALLOW() macros for most ioctls, just a few using a bad
+ * _IOC_TYPE value (i.e. not 'f') so that "early exit" type checks work.
+ */
+#define OBD_IOC_CMD_LATE(cmd, name) unlikely(cmd == name)
+#define OBD_IOC_CMD_GONE(cmd, name) (false)
+
+#ifdef OBD_IOC_BARRIER
+#define OBD_IOC_BARRIER_ALLOW(cmd) OBD_IOC_CMD_LATE(cmd, OBD_IOC_BARRIER)
+#else
+#define OBD_IOC_BARRIER_ALLOW(cmd) OBD_IOC_CMD_GONE(cmd)
+#endif
+#ifdef IOC_OSC_SET_ACTIVE
+#define IOC_OSC_SET_ACTIVE_ALLOW(cmd) OBD_IOC_CMD_LATE(cmd, IOC_OSC_SET_ACTIVE)
+#else
+#define IOC_OSC_SET_ACTIVE_ALLOW(cmd) OBD_IOC_CMD_GONE(cmd)
+#endif
+
+#endif /* __LUSTRE_IOCTL_OLD_H */
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/lustre/lustre_idl.h>
+#include <linux/lustre/lustre_ver.h>
/*
* sparse kernel source annotations
#define OBD_IOC_CREATE _IOWR('f', 101, OBD_IOC_DATA_TYPE)
#define OBD_IOC_DESTROY _IOW('f', 104, OBD_IOC_DATA_TYPE)
-/* OBD_IOC_PREALLOCATE _IOWR('f', 105, OBD_IOC_DATA_TYPE) */
+#define OBD_IOC_BARRIER_V2 _IOW('f', 105, struct obd_ioctl_data)
+#define OBD_IOC_SET_ACTIVE _IOW('f', 106, struct obd_ioctl_data)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 19, 53, 0)
+/* for API compatibility until 2.19.x, but prefer to use new IOC values above */
+/* OBD_IOC_BARRIER wrongly defined as _IOWR('f', 261, OBD_IOC_DATA_TYPE) */
+#define OBD_IOC_BARRIER _IOWR('g', 5, OBD_IOC_DATA_TYPE) /* < 2.16 */
+#define IOC_OSC_SET_ACTIVE _IOWR('h', 21, void *) /* deprecated 2.16 */
+#endif
#define OBD_IOC_SETATTR _IOW('f', 107, OBD_IOC_DATA_TYPE)
#define OBD_IOC_GETATTR _IOWR('f', 108, OBD_IOC_DATA_TYPE)
#define OBD_IOC_GETDTNAME _IOR('f', 127, char[MAX_OBD_NAME])
/* ioctl codes 128-143 are reserved for fsverity */
#define OBD_IOC_UUID2DEV _IOWR('f', 130, OBD_IOC_DATA_TYPE)
-#define OBD_IOC_GETNAME_OLD _IOWR('f', 131, OBD_IOC_DATA_TYPE)
#define OBD_IOC_GETMDNAME _IOR('f', 131, char[MAX_OBD_NAME])
-/* OBD_IOC_LOV_GET_CONFIG _IOWR('f', 132, OBD_IOC_DATA_TYPE) until 2.14 */
#define OBD_IOC_CLIENT_RECOVER _IOW('f', 133, OBD_IOC_DATA_TYPE)
/* ioctl codes 128-143 are reserved for fsverity */
-/* FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) */
-/* FS_IOC_MEASURE_VERITY _IOW('f', 134, struct fsverity_digest) */
-/* was OBD_IOC_NO_TRANSNO _IOW('f', 140, OBD_IOC_DATA_TYPE) until 2.14 */
#define OBD_IOC_SET_READONLY _IOW('f', 141, OBD_IOC_DATA_TYPE)
#define OBD_IOC_ABORT_RECOVERY _IOR('f', 142, OBD_IOC_DATA_TYPE)
enum obd_abort_recovery_flags {
OBD_FLG_ABORT_RECOV_MDT = 0x40000, /* LMD_FLG_ABORT_RECOV_MDT */
};
/* ioctl codes 128-143 are reserved for fsverity */
-#define OBD_GET_VERSION _IOWR('f', 144, OBD_IOC_DATA_TYPE)
-/* OBD_IOC_GSS_SUPPORT _IOWR('f', 145, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_CLOSE_UUID _IOWR('f', 147, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_CHANGELOG_SEND _IOW('f', 148, OBD_IOC_DATA_TYPE) */
#define OBD_IOC_GETDEVICE _IOWR('f', 149, OBD_IOC_DATA_TYPE)
#define OBD_IOC_FID2PATH _IOWR('f', 150, OBD_IOC_DATA_TYPE)
-/* lustre/lustre_user.h 151-153 */
-/* OBD_IOC_LOV_SETSTRIPE 154 LL_IOC_LOV_SETSTRIPE */
-/* OBD_IOC_LOV_GETSTRIPE 155 LL_IOC_LOV_GETSTRIPE */
-/* OBD_IOC_LOV_SETEA 156 LL_IOC_LOV_SETEA */
-/* lustre/lustre_user.h 157-159 */
-/* OBD_IOC_QUOTACHECK _IOW('f', 160, int) */
-/* OBD_IOC_POLL_QUOTACHECK _IOR('f', 161, struct if_quotacheck *) */
+/* lustre/lustre_user.h 151-159 */
#define OBD_IOC_QUOTACTL _IOWR('f', 162, struct if_quotactl)
/* lustre/lustre_user.h 163-176 */
#define OBD_IOC_CHANGELOG_REG _IOW('f', 177, struct obd_ioctl_data)
#define OBD_IOC_CHANGELOG_DEREG _IOW('f', 178, struct obd_ioctl_data)
#define OBD_IOC_CHANGELOG_CLEAR _IOW('f', 179, struct obd_ioctl_data)
-/* OBD_IOC_RECORD _IOWR('f', 180, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_ENDRECORD _IOWR('f', 181, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_PARSE _IOWR('f', 182, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_DORECORD _IOWR('f', 183, OBD_IOC_DATA_TYPE) */
#define OBD_IOC_PROCESS_CFG _IOWR('f', 184, OBD_IOC_DATA_TYPE)
-/* OBD_IOC_DUMP_LOG _IOWR('f', 185, OBD_IOC_DATA_TYPE) */
-/* OBD_IOC_CLEAR_LOG _IOWR('f', 186, OBD_IOC_DATA_TYPE) */
#define OBD_IOC_PARAM _IOW('f', 187, OBD_IOC_DATA_TYPE)
#define OBD_IOC_POOL _IOWR('f', 188, OBD_IOC_DATA_TYPE)
#define OBD_IOC_REPLACE_NIDS _IOWR('f', 189, OBD_IOC_DATA_TYPE)
#define OBD_IOC_LLOG_CANCEL _IOWR('f', 193, OBD_IOC_DATA_TYPE)
#define OBD_IOC_LLOG_REMOVE _IOWR('f', 194, OBD_IOC_DATA_TYPE)
#define OBD_IOC_LLOG_CHECK _IOWR('f', 195, OBD_IOC_DATA_TYPE)
-/* OBD_IOC_LLOG_CATINFO _IOWR('f', 196, OBD_IOC_DATA_TYPE) */
#define OBD_IOC_NODEMAP _IOWR('f', 197, OBD_IOC_DATA_TYPE)
#define OBD_IOC_CLEAR_CONFIGS _IOWR('f', 198, OBD_IOC_DATA_TYPE)
-
-/* ECHO_IOC_GET_STRIPE _IOWR('f', 200, OBD_IOC_DATA_TYPE) */
-/* ECHO_IOC_SET_STRIPE _IOWR('f', 201, OBD_IOC_DATA_TYPE) */
-/* ECHO_IOC_ENQUEUE _IOWR('f', 202, OBD_IOC_DATA_TYPE) */
-/* ECHO_IOC_CANCEL _IOWR('f', 203, OBD_IOC_DATA_TYPE) */
-
#define OBD_IOC_LCFG_FORK _IOWR('f', 208, OBD_IOC_DATA_TYPE)
#define OBD_IOC_LCFG_ERASE _IOWR('f', 209, OBD_IOC_DATA_TYPE)
#define OBD_IOC_GET_OBJ_VERSION _IOR('f', 210, OBD_IOC_DATA_TYPE)
-
/* lustre/lustre_user.h 211-220 */
-/* was #define OBD_IOC_GET_MNTOPT _IOW('f', 220, mntopt_t) until 2.11 */
#define OBD_IOC_ECHO_MD _IOR('f', 221, struct obd_ioctl_data)
#define OBD_IOC_ECHO_ALLOC_SEQ _IOWR('f', 222, struct obd_ioctl_data)
#define OBD_IOC_START_LFSCK _IOWR('f', 230, OBD_IOC_DATA_TYPE)
#define OBD_IOC_STOP_LFSCK _IOW('f', 231, OBD_IOC_DATA_TYPE)
#define OBD_IOC_QUERY_LFSCK _IOR('f', 232, struct obd_ioctl_data)
#define OBD_IOC_CHLG_POLL _IOR('f', 233, long)
-/* lustre/lustre_user.h 240-249 */
-/* was LIBCFS_IOC_DEBUG_MASK _IOWR('f', 250, long) until 2.11 */
-
-/* OBD_IOC_BARRIER wrongly defined as _IOWR('f', 261, OBD_IOC_DATA_TYPE) */
-#define OBD_IOC_BARRIER _IOWR('g', 5, OBD_IOC_DATA_TYPE)
-
-#define IOC_OSC_SET_ACTIVE _IOWR('h', 21, void *)
+/* lustre/lustre_user.h 240-253 */
#endif /* _UAPI_LUSTRE_IOCTL_H */
#define LL_IOC_LOV_GETSTRIPE _IOW ('f', 155, long)
#define LL_IOC_LOV_GETSTRIPE_NEW _IOR('f', 155, struct lov_user_md)
#define LL_IOC_LOV_SETEA _IOW ('f', 156, long)
-/* LL_IOC_RECREATE_OBJ 157 obsolete */
-/* LL_IOC_RECREATE_FID 157 obsolete */
#define LL_IOC_GROUP_LOCK _IOW ('f', 158, long)
#define LL_IOC_GROUP_UNLOCK _IOW ('f', 159, long)
-/* LL_IOC_QUOTACHECK 160 OBD_IOC_QUOTACHECK */
-/* LL_IOC_POLL_QUOTACHECK 161 OBD_IOC_POLL_QUOTACHECK */
-/* LL_IOC_QUOTACTL 162 OBD_IOC_QUOTACTL */
#define IOC_OBD_STATFS _IOWR('f', 164, struct obd_statfs *)
-/* IOC_LOV_GETINFO 165 obsolete */
#define LL_IOC_FLUSHCTX _IOW ('f', 166, long)
-/* LL_IOC_RMTACL 167 obsolete */
#define LL_IOC_GETOBDCOUNT _IOR ('f', 168, long)
#define LL_IOC_LLOOP_ATTACH _IOWR('f', 169, long)
#define LL_IOC_LLOOP_DETACH _IOWR('f', 170, long)
struct lustre_swap_layouts)
#define LL_IOC_HSM_ACTION _IOR('f', 220, \
struct hsm_current_action)
-/* lustre_ioctl.h 221-232 */
+/* lustre_ioctl.h 221-233 */
#define LL_IOC_LMV_SETSTRIPE _IOWR('f', 240, struct lmv_user_md)
#define LL_IOC_LMV_GETSTRIPE _IOWR('f', 241, struct lmv_user_md)
#define LL_IOC_REMOVE_ENTRY _IOWR('f', 242, __u64)
#endif
#include <libcfs/linux/linux-misc.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#ifdef HAVE_UAPI_LINUX_MOUNT_H
#include <uapi/linux/mount.h>
#endif
}
case OBD_IOC_FID2PATH:
RETURN(ll_fid2path(inode, uarg));
- case OBD_IOC_GETNAME_OLD:
+#ifdef OBD_IOC_GETNAME_OLD
+ case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
+ sbi->ll_md_exp->exp_obd->obd_name, 2, 16);
+#endif
case OBD_IOC_GETDTNAME:
case OBD_IOC_GETMDNAME:
RETURN(ll_get_obd_name(inode, cmd, uarg));
OBD_ALLOC_PTR(ioc_data);
if (ioc_data) {
- obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
+ obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
sizeof *ioc_data, ioc_data, NULL);
- obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
+ obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
sizeof *ioc_data, ioc_data, NULL);
OBD_FREE_PTR(ioc_data);
#include <cl_object.h>
#include <lustre_fid.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <lustre_kernelcomm.h>
#include "lmv_internal.h"
RETURN(-ENOTTY);
/* exit early for unknown ioctl types */
- if (unlikely(_IOC_TYPE(cmd) != 'f' && cmd != IOC_OSC_SET_ACTIVE))
+ if (unlikely(_IOC_TYPE(cmd) != 'f' && !IOC_OSC_SET_ACTIVE_ALLOW(cmd)))
RETURN(OBD_IOC_ERROR(obd->obd_name, cmd, "unknown", -ENOTTY));
/* handle commands that don't use @karg first */
#include <lustre_dlm.h>
#include <lustre_fid.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <lustre_lib.h>
#include <lustre_mds.h>
#include <lustre_net.h>
CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n",
exp->exp_obd->obd_name, cmd, len, karg, uarg);
- /* exit early for unknown ioctl types */
- if (unlikely(_IOC_TYPE(cmd) != 'f' && cmd != IOC_OSC_SET_ACTIVE))
+ /* exit early for unknown ioctl types. */
+ if (unlikely(_IOC_TYPE(cmd) != 'f' && !IOC_OSC_SET_ACTIVE_ALLOW(cmd)))
RETURN(OBD_IOC_DEBUG(D_IOCTL, obd->obd_name, cmd, "unknown",
-ENOTTY));
#include <lustre_compat.h>
#include <lustre_fid.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <lustre_kernelcomm.h>
#include <lustre_lmv.h>
#include <lustre_log.h>
+#include <lustre_osc.h>
#include <lustre_swab.h>
#include <obd_class.h>
-#include <lustre_osc.h>
#include "mdc_internal.h"
if (rc < 0)
GOTO(out, rc);
GOTO(out, rc = 0);
- case IOC_OSC_SET_ACTIVE:
+#ifdef IOC_OSC_SET_ACTIVE
+ case_OBD_IOC_DEPRECATED_FT(IOC_OSC_SET_ACTIVE, obd->obd_name, 2, 17);
+#endif
+ case OBD_IOC_SET_ACTIVE:
rc = ptlrpc_set_import_active(imp, data->ioc_offset);
GOTO(out, rc);
/*
#include <obd_class.h>
#include <lprocfs_status.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <uapi/linux/lustre/lustre_param.h>
#include <uapi/linux/lustre/lustre_barrier_user.h>
case OBD_IOC_POOL:
rc = mgs_iocontrol_pool(&env, mgs, data);
break;
- case OBD_IOC_BARRIER:
+#ifdef OBD_IOC_BARRIER
+ case_OBD_IOC_DEPRECATED_FT(OBD_IOC_BARRIER, obd->obd_name, 2, 17);
+#endif
+ case OBD_IOC_BARRIER_V2:
rc = mgs_iocontrol_barrier(&env, mgs, data);
break;
case OBD_IOC_NODEMAP:
#endif /* HAVE_SERVER_SUPPORT */
#include <uapi/linux/lustre/lustre_ioctl.h>
#include "llog_internal.h"
+#include <lustre_ioctl_old.h>
#ifdef CONFIG_PROC_FS
static __u64 obd_max_alloc;
ENTRY;
CDEBUG(D_IOCTL, "obdclass: cmd=%x len=%u uarg=%pK\n", cmd, len, uarg);
- if (unlikely(_IOC_TYPE(cmd) != 'f' && cmd != IOC_OSC_SET_ACTIVE &&
- cmd != OBD_IOC_BARRIER))
+ if (unlikely(_IOC_TYPE(cmd) != 'f' && !OBD_IOC_BARRIER_ALLOW(cmd) &&
+ !IOC_OSC_SET_ACTIVE_ALLOW(cmd)))
RETURN(OBD_IOC_ERROR(obd->obd_name, cmd, "unknown", -ENOTTY));
rc = obd_ioctl_getdata(&data, &len, uarg);
GOTO(out, rc);
}
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
- case OBD_GET_VERSION: {
- static bool warned;
-
+#ifdef OBD_GET_VERSION
+ case_OBD_IOC_DEPRECATED(OBD_GET_VERSION, "obdclass", 2, 15)
if (!data->ioc_inlbuf1) {
rc = OBD_IOC_ERROR("obdclass", cmd, "no buffer passed",
-EINVAL);
GOTO(out, rc);
}
- if (!warned) {
- warned = true;
- CWARN("%s: ioctl(OBD_GET_VERSION) is deprecated, "
- "use llapi_get_version_string() and/or relink\n",
- current->comm);
- }
memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
strlen(LUSTRE_VERSION_STRING) + 1);
if (copy_to_user(uarg, data, len))
rc = -EFAULT;
GOTO(out, rc);
- }
#endif
case OBD_IOC_NAME2DEV: {
/* Resolve device name, does not change current selected dev */
#include <lustre_fid.h>
#include <lustre_ha.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <lustre_net.h>
#include <lustre_obdo.h>
+#include <lustre_osc.h>
#include <obd.h>
#include <obd_cksum.h>
#include <obd_class.h>
-#include <lustre_osc.h>
-#include <linux/falloc.h>
#include "osc_internal.h"
#include <lnet/lnet_rdma.h>
data = karg;
rc = obd_getattr(NULL, exp, &data->ioc_obdo1);
break;
- case IOC_OSC_SET_ACTIVE:
+#ifdef IOC_OSC_SET_ACTIVE
+ case_OBD_IOC_DEPRECATED_FT(IOC_OSC_SET_ACTIVE, obd->obd_name, 2, 17);
+#endif
+ case OBD_IOC_SET_ACTIVE:
if (unlikely(karg == NULL)) {
OBD_IOC_ERROR(obd->obd_name, cmd, "karg=NULL",
rc = -EINVAL);
#include <linux/kthread.h>
#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
#include <lustre_log.h>
#include <lustre_obdo.h>
#include <uapi/linux/lustre/lustre_param.h>
if (rc > 0)
rc = 0;
break;
- case IOC_OSC_SET_ACTIVE:
+#ifdef IOC_OSC_SET_ACTIVE
+ case_OBD_IOC_DEPRECATED_FT(IOC_OSC_SET_ACTIVE, obd->obd_name, 2, 17);
+#endif
+ case OBD_IOC_SET_ACTIVE:
rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
data->ioc_offset);
break;
liblustreapi_mirror.c liblustreapi_fid.c \
liblustreapi_ladvise.c liblustreapi_chlg.c \
liblustreapi_heat.c liblustreapi_pcc.c \
- liblustreapi_root.c \
+ liblustreapi_ioctl.c liblustreapi_root.c \
liblustreapi_lseek.c liblustreapi_swap.c
liblustreapi_la_CFLAGS = -fPIC -D_GNU_SOURCE $(LIBNL3_CFLAGS) \
-I $(top_builddir)/lnet/utils \
return 0;
}
-int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len)
-{
- struct obd_ioctl_data *overlay;
- char *ptr;
-
- data->ioc_len = obd_ioctl_packlen(data);
- data->ioc_version = OBD_IOCTL_VERSION;
-
- if (*pbuf != NULL && data->ioc_len > max_len) {
- llapi_error(LLAPI_MSG_ERROR, -EINVAL,
- "pbuf = %p, ioc_len = %u, max_len = %d",
- *pbuf, data->ioc_len, max_len);
- return -EINVAL;
- }
-
- if (*pbuf == NULL)
- *pbuf = malloc(data->ioc_len);
-
- if (*pbuf == NULL)
- return -ENOMEM;
-
- overlay = (struct obd_ioctl_data *)*pbuf;
- memcpy(*pbuf, data, sizeof(*data));
-
- ptr = overlay->ioc_bulk;
- if (data->ioc_inlbuf1) {
- memcpy(ptr, data->ioc_inlbuf1, data->ioc_inllen1);
- ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
- }
-
- if (data->ioc_inlbuf2) {
- memcpy(ptr, data->ioc_inlbuf2, data->ioc_inllen2);
- ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
- }
-
- if (data->ioc_inlbuf3) {
- memcpy(ptr, data->ioc_inlbuf3, data->ioc_inllen3);
- ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
- }
-
- if (data->ioc_inlbuf4) {
- memcpy(ptr, data->ioc_inlbuf4, data->ioc_inllen4);
- ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
- }
-
- return 0;
-}
-
-int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
-{
- struct obd_ioctl_data *overlay;
- char *ptr;
-
- if (pbuf == NULL)
- return -EINVAL;
-
- overlay = (struct obd_ioctl_data *)pbuf;
-
- /* Preserve the caller's buffer pointers */
- overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
- overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
- overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
- overlay->ioc_inlbuf4 = data->ioc_inlbuf4;
-
- memcpy(data, pbuf, sizeof(*data));
-
- ptr = overlay->ioc_bulk;
- if (data->ioc_inlbuf1) {
- memcpy(data->ioc_inlbuf1, ptr, data->ioc_inllen1);
- ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
- }
-
- if (data->ioc_inlbuf2) {
- memcpy(data->ioc_inlbuf2, ptr, data->ioc_inllen2);
- ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
- }
-
- if (data->ioc_inlbuf3) {
- memcpy(data->ioc_inlbuf3, ptr, data->ioc_inllen3);
- ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
- }
-
- if (data->ioc_inlbuf4) {
- memcpy(data->ioc_inlbuf4, ptr, data->ioc_inllen4);
- ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
- }
-
- return 0;
-}
-
/**
* Verify the setstripe parameters before using.
* This is a pair method for comp_args_to_layout()/llapi_layout_sanity_cb()
int rc;
rc = ioctl(fd, OBD_IOC_GETDTNAME, lov_name);
- if (rc && errno == ENOTTY)
- rc = ioctl(fd, OBD_IOC_GETNAME_OLD, lov_name);
if (rc) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "cannot get lov name");
{
int rc;
- rc = ioctl(fd, OBD_IOC_GETMDNAME, lov_name);
+ rc = llapi_ioctl(fd, OBD_IOC_GETMDNAME, lov_name);
if (rc) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get lmv name.");
--- /dev/null
+/*
+ * LGPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public License
+ * (LGPL) version 2.1 or (at your discretion) any later version.
+ * (LGPL) version 2.1 accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * LGPL HEADER END
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ *
+ * lustre/utils/liblustreapi_ioctl.c
+ *
+ * lustreapi library for packing/unpacking obd_ioctl_data structure to
+ * send commands to different OBD devices. Mostly for internal use.
+ *
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2017, Intel Corporation.
+ *
+ * Copyright (c) 2023, DataDirect Networks Storage.
+ */
+
+#include <string.h>
+#include <stddef.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include <lustre/lustreapi.h>
+#include <libcfs/util/ioctl.h>
+#include <linux/lustre/lustre_ioctl.h>
+#include <lustre_ioctl_old.h>
+#include <linux/lustre/lustre_ver.h>
+
+int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len)
+{
+ struct obd_ioctl_data *overlay;
+ char *ptr;
+
+ data->ioc_len = obd_ioctl_packlen(data);
+ data->ioc_version = OBD_IOCTL_VERSION;
+
+ if (*pbuf != NULL && data->ioc_len > max_len) {
+ llapi_error(LLAPI_MSG_ERROR, -EINVAL,
+ "pbuf = %p, ioc_len = %u, max_len = %d",
+ *pbuf, data->ioc_len, max_len);
+ return -EINVAL;
+ }
+
+ if (*pbuf == NULL)
+ *pbuf = malloc(data->ioc_len);
+
+ if (*pbuf == NULL)
+ return -ENOMEM;
+
+ overlay = (struct obd_ioctl_data *)*pbuf;
+ memcpy(*pbuf, data, sizeof(*data));
+
+ ptr = overlay->ioc_bulk;
+ if (data->ioc_inlbuf1) {
+ memcpy(ptr, data->ioc_inlbuf1, data->ioc_inllen1);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
+ }
+
+ if (data->ioc_inlbuf2) {
+ memcpy(ptr, data->ioc_inlbuf2, data->ioc_inllen2);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
+ }
+
+ if (data->ioc_inlbuf3) {
+ memcpy(ptr, data->ioc_inlbuf3, data->ioc_inllen3);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
+ }
+
+ if (data->ioc_inlbuf4) {
+ memcpy(ptr, data->ioc_inlbuf4, data->ioc_inllen4);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
+ }
+
+ return 0;
+}
+
+/**
+ * Remap OBD device ioctl cmd to old one in case running with older modules.
+ * Replaces callers that use "l_ioctl(OBD_DEV_ID, ...)".
+ *
+ * \param dev_id Lustre device number (from 'lctl dl')
+ * \param cmd ioctl command
+ * \param buf ioctl data argument, usually obd_ioctl_data
+ */
+int llapi_ioctl_dev(unsigned int dev_id, unsigned int cmd, void *buf)
+{
+ unsigned int oldcmd;
+ int rc;
+
+ /* common case, ioctl works as expected */
+ rc = l_ioctl(dev_id, cmd, buf);
+ if (rc >= 0 || errno != ENOTTY)
+ return rc;
+
+ switch (cmd) {
+ /*
+ * Use #ifdef instead of version check to minimize the places that a
+ * version change might cause a compiler error in the future.
+ *
+ * Version in comment is to allow finding this code for later removal.
+ */
+#ifdef OBD_IOC_BARRIER /* < OBD_OCD_VERSION(2, 19, 53, 0) */
+ case OBD_IOC_BARRIER_V2:
+ oldcmd = OBD_IOC_BARRIER;
+ break;
+#endif
+#ifdef IOC_OSC_SET_ACTIVE /* < OBD_OCD_VERSION(2, 19, 53, 0) */
+ case OBD_IOC_SET_ACTIVE:
+ oldcmd = IOC_OSC_SET_ACTIVE;
+ break;
+#endif
+ default:
+ oldcmd = 0;
+ break;
+ }
+ if (oldcmd)
+ rc = l_ioctl(dev_id, oldcmd, buf);
+
+ return rc;
+}
+
+/**
+ * Remap regular file ioctl cmd to old one in case running with older modules.
+ * Replaces callers that use "ioctl(fd, ...)".
+ *
+ * \param fd open file descriptor
+ * \param cmd ioctl command
+ * \param buf ioctl data argument
+ */
+int llapi_ioctl(int fd, unsigned int cmd, void *buf)
+{
+ unsigned int oldcmd;
+ int rc;
+
+ if (fd < 0)
+ return -EBADF;
+
+ /* common case, ioctl works as expected */
+ rc = ioctl(fd, cmd, buf);
+ if (rc >= 0 || errno != ENOTTY)
+ return rc;
+
+ switch (cmd) {
+ /*
+ * Use #ifdef instead of version check to minimize the places that a
+ * version change might cause a compiler error in the future.
+ *
+ * Version in comment is to allow finding this code for later removal.
+ */
+#ifdef OBD_IOC_GETNAME_OLD /* < OBD_OCD_VERSION(2, 18, 53, 0) */
+ case OBD_IOC_GETMDNAME:
+ oldcmd = OBD_IOC_GETNAME_OLD;
+ break;
+#endif
+ default:
+ oldcmd = 0;
+ break;
+ }
+ if (oldcmd)
+ rc = ioctl(fd, oldcmd, buf);
+
+ return rc;
+}
+
+int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len)
+{
+ struct obd_ioctl_data *overlay;
+ char *ptr;
+
+ if (pbuf == NULL)
+ return -EINVAL;
+
+ overlay = (struct obd_ioctl_data *)pbuf;
+
+ /* Preserve the caller's buffer pointers */
+ overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
+ overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
+ overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
+ overlay->ioc_inlbuf4 = data->ioc_inlbuf4;
+
+ memcpy(data, pbuf, sizeof(*data));
+
+ ptr = overlay->ioc_bulk;
+ if (data->ioc_inlbuf1) {
+ memcpy(data->ioc_inlbuf1, ptr, data->ioc_inllen1);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen1, 8);
+ }
+
+ if (data->ioc_inlbuf2) {
+ memcpy(data->ioc_inlbuf2, ptr, data->ioc_inllen2);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen2, 8);
+ }
+
+ if (data->ioc_inlbuf3) {
+ memcpy(data->ioc_inlbuf3, ptr, data->ioc_inllen3);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen3, 8);
+ }
+
+ if (data->ioc_inlbuf4) {
+ memcpy(data->ioc_inlbuf4, ptr, data->ioc_inllen4);
+ ptr += __ALIGN_KERNEL(data->ioc_inllen4, 8);
+ }
+
+ return 0;
+}
int get_root_path(int want, char *fsname, int *outfd, char *path, int index,
dev_t *dev, char *nid);
int llapi_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, int max_len);
+int llapi_ioctl_dev(int dev_id, unsigned int cmd, void *buf);
int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len);
int sattr_cache_get_defaults(const char *const fsname,
const char *const pathname, unsigned int *scount,
jt_cmdname(argv[0]));
return rc;
}
- rc = l_ioctl(OBD_DEV_ID, IOC_OSC_SET_ACTIVE, buf);
+ rc = llapi_ioctl_dev(OBD_DEV_ID, OBD_IOC_SET_ACTIVE, buf);
if (rc)
fprintf(stderr, "error: %s: failed: %s\n",
jt_cmdname(argv[0]), strerror(rc = errno));
return rc;
}
- rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
+ rc = llapi_ioctl_dev(OBD_DEV_ID, OBD_IOC_BARRIER_V2, buf);
if (rc < 0)
fprintf(stderr, "Fail to freeze barrier for %s: %s\n",
argv[1], strerror(errno));
return rc;
}
- rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
+ rc = llapi_ioctl_dev(OBD_DEV_ID, OBD_IOC_BARRIER_V2, buf);
if (rc < 0)
fprintf(stderr, "Fail to thaw barrier for %s: %s\n",
argv[1], strerror(errno));
return rc;
}
- rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
+ rc = llapi_ioctl_dev(OBD_DEV_ID, OBD_IOC_BARRIER_V2, buf);
if (rc < 0)
fprintf(stderr, "Fail to query barrier for %s: %s\n",
fsname, strerror(errno));
return rc;
}
- rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf);
+ rc = llapi_ioctl_dev(OBD_DEV_ID, OBD_IOC_BARRIER_V2, buf);
if (rc < 0) {
fprintf(stderr, "Fail to rescan barrier bitmap for %s: %s\n",
argv[1], strerror(errno));
#include <linux/lnet/socklnd.h>
#include <lnetconfig/liblnetconfig.h>
#include <lustre/lustreapi.h>
+#include <lustre_ioctl_old.h>
unsigned int libcfs_debug;
unsigned int libcfs_printk = D_CANTMASK;
int
jt_ptl_list_nids(int argc, char **argv)
{
- struct libcfs_ioctl_data data;
int all = 0, return_nid = 0;
yaml_emitter_t request;
yaml_parser_t reply;
struct nl_sock *sk;
bool done = false;
int rc = 0;
- int count;
all = (argc == 2) && (strcmp(argv[1], "all") == 0);
/* Hack to pass back value */
if (rc == 0)
yaml_parser_log_error(&reply, stderr, NULL);
yaml_parser_delete(&reply);
-old_api:
+old_api: {
+#ifdef IOC_LIBCFS_GET_NI
+ int count;
+
if (sk)
nl_socket_free(sk);
if (rc == 1)
return 0;
for (count = 0;; count++) {
+ struct libcfs_ioctl_data data;
+
LIBCFS_IOC_INIT(data);
data.ioc_count = count;
rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data);
}
}
- return 0;
+#else
+ rc = -1;
+#endif
+ }
+ return rc;
}
int
int rc;
int timeout;
struct lnet_process_id id;
- struct lnet_process_id ids[LNET_INTERFACES_MAX_DEFAULT];
- lnet_nid_t src = LNET_NID_ANY;
- int maxids = sizeof(ids) / sizeof(ids[0]);
- struct lnet_ioctl_ping_data ping = { { 0 } };
yaml_emitter_t request;
yaml_parser_t reply;
yaml_event_t event;
struct nl_sock *sk;
char *sep;
- int i;
if (argc < 2) {
fprintf(stderr, "usage: %s id [timeout (secs)]\n", argv[0]);
nl_socket_free(sk);
return rc;
old_api:
+#ifdef IOC_LIBCFS_PING_PEER
+ {
+ struct lnet_process_id ids[LNET_INTERFACES_MAX_DEFAULT];
+ int maxids = sizeof(ids) / sizeof(ids[0]);
+ struct lnet_ioctl_ping_data ping = { { 0 } };
+ int i;
+
if (sk)
nl_socket_free(sk);
LIBCFS_IOC_INIT_V2(ping, ping_hdr);
ping.ping_hdr.ioc_len = sizeof(ping);
ping.ping_id = id;
- ping.ping_src = src;
+ ping.ping_src = LNET_NID_ANY;
ping.op_param = timeout;
ping.ping_count = maxids;
ping.ping_buf = ids;
if (ping.ping_count > maxids)
printf("%d out of %d ids listed\n", maxids, ping.ping_count);
-
- return 0;
+ }
+#else
+ rc = -ENOTTY;
+#endif
+ return rc;
}
int jt_ptl_mynid(int argc, char **argv)