From f10371aecfb4aeb7fd972eac5eeb6b7318ad3fc6 Mon Sep 17 00:00:00 2001 From: yangsheng Date: Wed, 17 Dec 2008 04:49:58 +0000 Subject: [PATCH] Branch HEAD b=16208 i=adilger, johann Implement OBD_PING use ioctl() instead of /proc. --- lustre/include/lustre/liblustreapi.h | 2 ++ lustre/include/lustre_lib.h | 1 + lustre/include/lustre_net.h | 2 ++ lustre/include/obd.h | 1 + lustre/mdc/mdc_request.c | 3 +++ lustre/obdclass/class_obd.c | 11 ++++++++-- lustre/osc/osc_request.c | 3 +++ lustre/ptlrpc/lproc_ptlrpc.c | 7 +------ lustre/ptlrpc/pinger.c | 39 ++++++++++++++++++++++++++++++++---- lustre/utils/lfs.c | 3 ++- lustre/utils/obd.c | 29 +++++++++++++++++++++++++++ 11 files changed, 88 insertions(+), 13 deletions(-) diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index b82d3b3..7dbe8c7 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -156,6 +156,8 @@ extern int parse_size(char *optarg, unsigned long long *size, unsigned long long *size_units, int bytes_spec); extern int llapi_path2fid(const char *path, unsigned long long *seq, unsigned long *oid, unsigned long *ver); +extern void llapi_ping_target(char *obd_type, char *obd_name, + char *obd_uuid, void *args); struct mntent; #define HAVE_LLAPI_IS_LUSTRE_MNT diff --git a/lustre/include/lustre_lib.h b/lustre/include/lustre_lib.h index 73d45d3..2ec0f44 100644 --- a/lustre/include/lustre_lib.h +++ b/lustre/include/lustre_lib.h @@ -463,6 +463,7 @@ static inline void obd_ioctl_freedata(char *buf, int len) #define OBD_IOC_LOV_GET_CONFIG _IOWR('f', 132, OBD_IOC_DATA_TYPE) #define OBD_IOC_CLIENT_RECOVER _IOW ('f', 133, OBD_IOC_DATA_TYPE) +#define OBD_IOC_PING_TARGET _IOW ('f', 136, OBD_IOC_DATA_TYPE) #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 139 ) #define OBD_IOC_NO_TRANSNO _IOW ('f', 140, OBD_IOC_DATA_TYPE) diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index f3ebcd4..efef5b4 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -1279,6 +1279,8 @@ int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid); /* ptlrpc/pinger.c */ int ptlrpc_pinger_add_import(struct obd_import *imp); int ptlrpc_pinger_del_import(struct obd_import *imp); +struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp); +int ptlrpc_obd_ping(struct obd_device *obd); cfs_time_t ptlrpc_suspend_wakeup_time(void); #ifdef __KERNEL__ void ping_evictor_start(void); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index cf5979c..12daa90 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -946,6 +946,7 @@ struct obd_llog_group { /* corresponds to one of the obd's */ #define MAX_OBD_NAME 128 #define OBD_DEVICE_MAGIC 0XAB5CD6EF +#define OBD_DEV_BY_DEVNAME 0xffffd0de struct obd_device { struct obd_type *obd_type; __u32 obd_magic; diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index f23e8a4..48c79ee 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -1064,6 +1064,9 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, rc = lquota_poll_check(quota_interface, exp, (struct if_quotacheck *)karg); GOTO(out, rc); + case OBD_IOC_PING_TARGET: + rc = ptlrpc_obd_ping(obd); + GOTO(out, rc); default: CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd); GOTO(out, rc = -ENOTTY); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index d5bbe44..29ca59b 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -308,12 +308,19 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) } - if (data->ioc_dev >= class_devno_max()) { + if (data->ioc_dev == OBD_DEV_BY_DEVNAME) { + if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL) + GOTO(out, err = -EINVAL); + if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME) + GOTO(out, err = -EINVAL); + obd = class_name2obd(data->ioc_inlbuf4); + } else if (data->ioc_dev < class_devno_max()) { + obd = class_num2obd(data->ioc_dev); + } else { CERROR("OBD ioctl: No device\n"); GOTO(out, err = -EINVAL); } - obd = class_num2obd(data->ioc_dev); if (obd == NULL) { CERROR("OBD ioctl : No Device %d\n", data->ioc_dev); GOTO(out, err = -EINVAL); diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 9bf1afa..6b270a6 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -3407,6 +3407,9 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, err = lquota_poll_check(quota_interface, exp, (struct if_quotacheck *)karg); GOTO(out, err); + case OBD_IOC_PING_TARGET: + err = ptlrpc_obd_ping(obd); + GOTO(out, err); default: CDEBUG(D_INODE, "unrecognised ioctl %#x by %s\n", cmd, cfs_curproc_comm()); diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index d5af015..5c3aaca 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -696,17 +696,12 @@ int lprocfs_wr_ping(struct file *file, const char *buffer, ENTRY; LPROCFS_CLIMP_CHECK(obd); - req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_OBD_PING, - LUSTRE_OBD_VERSION, OBD_PING); - + req = ptlrpc_prep_ping(obd->u.cli.cl_import); LPROCFS_CLIMP_EXIT(obd); if (req == NULL) RETURN(-ENOMEM); - ptlrpc_request_set_replen(req); req->rq_send_state = LUSTRE_IMP_FULL; - req->rq_no_resend = 1; - req->rq_no_delay = 1; rc = ptlrpc_queue_wait(req); diff --git a/lustre/ptlrpc/pinger.c b/lustre/ptlrpc/pinger.c index a9e4aba..7a15386 100644 --- a/lustre/ptlrpc/pinger.c +++ b/lustre/ptlrpc/pinger.c @@ -51,13 +51,46 @@ struct semaphore pinger_sem; static CFS_LIST_HEAD(pinger_imports); +struct ptlrpc_request * +ptlrpc_prep_ping(struct obd_import *imp) +{ + struct ptlrpc_request *req; + + req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, + LUSTRE_OBD_VERSION, OBD_PING); + if (req) { + ptlrpc_request_set_replen(req); + req->rq_no_resend = req->rq_no_delay = 1; + } + return req; +} + +int ptlrpc_obd_ping(struct obd_device *obd) +{ + int rc; + struct ptlrpc_request *req; + ENTRY; + + req = ptlrpc_prep_ping(obd->u.cli.cl_import); + if (req == NULL) + RETURN(-ENOMEM); + + req->rq_send_state = LUSTRE_IMP_FULL; + + rc = ptlrpc_queue_wait(req); + + ptlrpc_req_finished(req); + + RETURN(rc); +} +EXPORT_SYMBOL(ptlrpc_obd_ping); + int ptlrpc_ping(struct obd_import *imp) { struct ptlrpc_request *req; ENTRY; - req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, LUSTRE_OBD_VERSION, - OBD_PING); + req = ptlrpc_prep_ping(imp); if (req == NULL) { CERROR("OOM trying to ping %s->%s\n", imp->imp_obd->obd_uuid.uuid, @@ -67,8 +100,6 @@ int ptlrpc_ping(struct obd_import *imp) DEBUG_REQ(D_INFO, req, "pinging %s->%s", imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd)); - req->rq_no_resend = req->rq_no_delay = 1; - ptlrpc_request_set_replen(req); ptlrpcd_add_req(req, PSCOPE_OTHER); RETURN(0); diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index c8fcc6e..a498a08 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1245,7 +1245,8 @@ static int lfs_check(int argc, char **argv) return -1; } - rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir); + rc = llapi_target_iterate(num_types, obd_types, + mnt->mnt_dir, llapi_ping_target); if (rc) fprintf(stderr, "error: %s: %s status failed\n", diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index a7deb16..a408a9d 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -2929,3 +2929,32 @@ out: return rc; } + +void llapi_ping_target(char *obd_type, char *obd_name, + char *obd_uuid, void *args) +{ + int rc; + struct obd_ioctl_data data; + + memset(&data, 0, sizeof(data)); + data.ioc_inlbuf4 = obd_name; + data.ioc_inllen4 = strlen(obd_name) + 1; + data.ioc_dev = OBD_DEV_BY_DEVNAME; + memset(buf, 0, sizeof(rawbuf)); + if (obd_ioctl_pack(&data, &buf, max)) { + fprintf(stderr, "error: invalid ioctl\n"); + return; + } + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_PING_TARGET, buf); + if (rc) + rc = errno; + if (rc == ENOTCONN || rc == ESHUTDOWN) { + printf("%s inactive.\n", obd_name); + } else if (rc) { + fprintf(stderr, "error: check '%s' %s\n", + obd_name, strerror(errno)); + } else { + printf("%s active.\n", obd_name); + } + +} -- 1.8.3.1