From: Andreas Dilger Date: Sun, 19 Mar 2023 23:09:24 +0000 (-0600) Subject: LU-16634 obdclass: improve iocontrol error messages X-Git-Tag: 2.15.56~218 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=1f4825eff026321a8e769739868d4d482026c3ee;p=fs%2Flustre-release.git LU-16634 obdclass: improve iocontrol error messages Add consistent CDEBUG() messages for iocontrol handlers. Add helpers OBD_IOC_ERROR() and OBD_IOC_DEBUG() to print the iocontrol parameters consistently in case of an error. Signed-off-by: Andreas Dilger Change-Id: I1a0d2f839949debf346aa15c65b0f407e2ce7057 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50334 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Vitaliy Kuznetsov Reviewed-by: jsimmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 4033524..5a9bd43 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -2017,4 +2017,11 @@ struct attribute *get_attr_starts_with(const struct kobj_type *typ, return _get_attr_matches(typ, name, len, _attr_name_starts_with); } +int obd_ioctl_msg(const char *file, const char *func, int line, int level, + const char *name, unsigned int cmd, const char *msg, int rc); +#define OBD_IOC_DEBUG(level, dev, cmd, msg, rc) \ + obd_ioctl_msg(__FILE__, __func__, __LINE__, level, dev, cmd, msg, rc) +#define OBD_IOC_ERROR(dev, cmd, msg, rc) \ + obd_ioctl_msg(__FILE__, __func__, __LINE__, D_ERROR, dev, cmd, msg, rc) + #endif /* __LINUX_OBD_CLASS_H */ diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 9a2fc31..b820773 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1500,8 +1500,8 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) int rc = 0; ENTRY; - CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n", - PFID(ll_inode2fid(inode)), inode, cmd); + CDEBUG(D_VFSTRACE|D_IOCTL, "VFS Op:inode="DFID"(%pK) cmd=%x arg=%lx\n", + PFID(ll_inode2fid(inode)), inode, cmd, arg); /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */ if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */ @@ -2119,7 +2119,8 @@ out_quotactl: rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT), KEY_TGT_COUNT, &vallen, &count); if (rc) { - CERROR("get target count failed: %d\n", rc); + CERROR("%s: get target count failed: rc = %d\n", + sbi->ll_fsname, rc); RETURN(rc); } diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 0828c33..9428738 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -4174,8 +4174,8 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) int flags, rc; ENTRY; - CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%x\n", - PFID(ll_inode2fid(inode)), inode, cmd); + CDEBUG(D_VFSTRACE|D_IOCTL, "VFS Op:inode="DFID"(%pK) cmd=%x arg=%lx\n", + PFID(ll_inode2fid(inode)), inode, cmd, arg); ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1); /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */ @@ -4198,9 +4198,11 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (cmd == LL_IOC_SETFLAGS) { if ((flags & LL_FILE_IGNORE_LOCK) && !(file->f_flags & O_DIRECT)) { - CERROR("%s: unable to disable locking on " - "non-O_DIRECT file\n", current->comm); - RETURN(-EINVAL); + rc = -EINVAL; + CERROR("%s: unable to disable locking on non-O_DIRECT file "DFID": rc = %d\n", + current->comm, PFID(ll_inode2fid(inode)), + rc); + RETURN(rc); } fd->fd_flags |= flags; @@ -4970,60 +4972,64 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock) #endif switch (fl_type) { - case F_RDLCK: - einfo.ei_mode = LCK_PR; - break; - case F_UNLCK: - /* An unlock request may or may not have any relation to - * existing locks so we may not be able to pass a lock handle - * via a normal ldlm_lock_cancel() request. The request may even - * unlock a byte range in the middle of an existing lock. In - * order to process an unlock request we need all of the same - * information that is given with a normal read or write record - * lock request. To avoid creating another ldlm unlock (cancel) - * message we'll treat a LCK_NL flock request as an unlock. */ - einfo.ei_mode = LCK_NL; - break; - case F_WRLCK: - einfo.ei_mode = LCK_PW; - break; - default: - CDEBUG(D_INFO, "Unknown fcntl lock type: %d\n", fl_type); - RETURN (-ENOTSUPP); - } - - switch (cmd) { - case F_SETLKW: + case F_RDLCK: + einfo.ei_mode = LCK_PR; + break; + case F_UNLCK: + /* An unlock request may or may not have any relation to + * existing locks so we may not be able to pass a lock handle + * via a normal ldlm_lock_cancel() request. The request may even + * unlock a byte range in the middle of an existing lock. In + * order to process an unlock request we need all of the same + * information that is given with a normal read or write record + * lock request. To avoid creating another ldlm unlock (cancel) + * message we'll treat a LCK_NL flock request as an unlock. */ + einfo.ei_mode = LCK_NL; + break; + case F_WRLCK: + einfo.ei_mode = LCK_PW; + break; + default: + rc = -EINVAL; + CERROR("%s: fcntl from '%s' unknown lock type=%d: rc = %d\n", + sbi->ll_fsname, current->comm, fl_type, rc); + RETURN(rc); + } + + switch (cmd) { + case F_SETLKW: #ifdef F_SETLKW64 - case F_SETLKW64: + case F_SETLKW64: #endif - flags = 0; - break; - case F_SETLK: + flags = 0; + break; + case F_SETLK: #ifdef F_SETLK64 - case F_SETLK64: + case F_SETLK64: #endif - flags = LDLM_FL_BLOCK_NOWAIT; - break; - case F_GETLK: + flags = LDLM_FL_BLOCK_NOWAIT; + break; + case F_GETLK: #ifdef F_GETLK64 - case F_GETLK64: + case F_GETLK64: #endif - flags = LDLM_FL_TEST_LOCK; - break; - default: - CERROR("unknown fcntl lock command: %d\n", cmd); - RETURN (-EINVAL); - } + flags = LDLM_FL_TEST_LOCK; + break; + default: + rc = -EINVAL; + CERROR("%s: fcntl from '%s' unknown lock command=%d: rc = %d\n", + sbi->ll_fsname, current->comm, cmd, rc); + RETURN(rc); + } /* Save the old mode so that if the mode in the lock changes we * can decrement the appropriate reader or writer refcount. */ file_lock->fl_type = einfo.ei_mode; - op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0, - LUSTRE_OPC_ANY, NULL); - if (IS_ERR(op_data)) - RETURN(PTR_ERR(op_data)); + op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0, + LUSTRE_OPC_ANY, NULL); + if (IS_ERR(op_data)) + RETURN(PTR_ERR(op_data)); CDEBUG(D_DLMTRACE, "inode="DFID", pid=%u, flags=%#llx, mode=%u, " "start=%llu, end=%llu\n", PFID(ll_inode2fid(inode)), @@ -5042,12 +5048,12 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock) !(flags & LDLM_FL_TEST_LOCK)) rc2 = locks_lock_file_wait(file, file_lock); #else - if ((file_lock->fl_flags & FL_FLOCK) && - (rc == 0 || file_lock->fl_type == F_UNLCK)) + if ((file_lock->fl_flags & FL_FLOCK) && + (rc == 0 || file_lock->fl_type == F_UNLCK)) rc2 = flock_lock_file_wait(file, file_lock); - if ((file_lock->fl_flags & FL_POSIX) && - (rc == 0 || file_lock->fl_type == F_UNLCK) && - !(flags & LDLM_FL_TEST_LOCK)) + if ((file_lock->fl_flags & FL_POSIX) && + (rc == 0 || file_lock->fl_type == F_UNLCK) && + !(flags & LDLM_FL_TEST_LOCK)) rc2 = posix_lock_file_wait(file, file_lock); #endif /* HAVE_LOCKS_LOCK_FILE_WAIT */ diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 945061f..c5d6a9e 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -851,6 +851,8 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, int rc = 0; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + exp->exp_obd->obd_name, cmd, len, karg, uarg); if (count == 0) RETURN(-ENOTTY); @@ -1064,6 +1066,7 @@ hsm_req_err: } case LL_IOC_HSM_CT_START: { struct lustre_kernelcomm *lk = karg; + if (lk->lk_flags & LK_FLG_STOP) rc = lmv_hsm_ct_unregister(obd, cmd, len, lk, uarg); else @@ -1082,10 +1085,8 @@ hsm_req_err: err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg); if (err) { if (tgt->ltd_active) { - CERROR("error: iocontrol MDC %s on MDT" - " idx %d cmd %x: err = %d\n", - tgt->ltd_uuid.uuid, - tgt->ltd_index, cmd, err); + OBD_IOC_ERROR(obd->obd_name, cmd, + tgt->ltd_uuid.uuid, err); if (!rc) rc = err; } diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index f0c7075..a7364cf 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -2743,6 +2743,9 @@ static int lod_iocontrol(unsigned int cmd, struct obd_export *exp, int len, int rc; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); + rc = lu_env_init(&env, LCT_LOCAL | LCT_MD_THREAD); if (rc) { CERROR("%s: can't initialize env: rc = %d\n", @@ -2774,9 +2777,8 @@ static int lod_iocontrol(unsigned int cmd, struct obd_export *exp, int len, rc = lod_llog_cancel(&env, lod); break; default: - CERROR("%s: unrecognized ioctl %#x by %s\n", - obd->obd_name, cmd, current->comm); - rc = -ENOTTY; + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } lu_env_fini(&env); diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 04cc3ad..8af1b53 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -954,6 +954,9 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len, int i = 0, rc = 0, count = lov->desc.ld_tgt_count; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + exp->exp_obd->obd_name, cmd, len, karg, uarg); + switch (cmd) { case IOC_OBD_STATFS: { struct obd_ioctl_data *data = karg; @@ -1081,11 +1084,11 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len, len, karg, uarg); if (err) { if (lov->lov_tgts[i]->ltd_active) { - CDEBUG_LIMIT(err == -ENOTTY ? - D_IOCTL : D_WARNING, - "iocontrol OSC %s on OST idx %d cmd %x: err = %d\n", - lov_uuid2str(lov, i), - i, cmd, err); + OBD_IOC_DEBUG(err == -ENOTTY ? + D_IOCTL : D_WARNING, + obd->obd_name, cmd, + lov_uuid2str(lov, i), + err); if (!rc) rc = err; } diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 32a54c9..4442efb 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -2190,7 +2190,10 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, struct obd_ioctl_data *data = karg; struct obd_import *imp = obd->u.cli.cl_import; int rc; + ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); if (!try_module_get(THIS_MODULE)) { CERROR("%s: cannot get module '%s'\n", obd->obd_name, @@ -2291,8 +2294,8 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, rc = mdc_ioc_swap_layouts(exp, karg); GOTO(out, rc); default: - CERROR("unrecognised ioctl: cmd = %#x\n", cmd); - GOTO(out, rc = -ENOTTY); + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } out: module_put(THIS_MODULE); diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 18cefa3..396c422 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -2267,12 +2267,16 @@ static int mdd_changelog_user_deregister(const struct lu_env *env, * \param karg - ioctl data, in kernel space */ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, - unsigned int cmd, int len, void *karg) + unsigned int cmd, int len, void *karg) { struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); + struct obd_device *obd = mdd2obd_dev(mdd); struct obd_ioctl_data *data = karg; - int rc; + int rc = -EINVAL; + ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK\n", + obd->obd_name, cmd, len, karg); /* Doesn't use obd_ioctl_data */ switch (cmd) { @@ -2282,24 +2286,20 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, if (unlikely(!barrier_entry(mdd->mdd_bottom))) RETURN(-EINPROGRESS); - rc = mdd_changelog_clear(env, mdd, cs->cs_id, - cs->cs_recno); + rc = mdd_changelog_clear(env, mdd, cs->cs_id, cs->cs_recno); barrier_exit(mdd->mdd_bottom); RETURN(rc); } case OBD_IOC_START_LFSCK: { - rc = lfsck_start(env, mdd->mdd_bottom, - (struct lfsck_start_param *)karg); + rc = lfsck_start(env, mdd->mdd_bottom, karg); RETURN(rc); } case OBD_IOC_STOP_LFSCK: { - rc = lfsck_stop(env, mdd->mdd_bottom, - (struct lfsck_stop *)karg); + rc = lfsck_stop(env, mdd->mdd_bottom, karg); RETURN(rc); } case OBD_IOC_QUERY_LFSCK: { - rc = lfsck_query(env, mdd->mdd_bottom, NULL, NULL, - (struct lfsck_query *)karg); + rc = lfsck_query(env, mdd->mdd_bottom, NULL, NULL, karg); RETURN(rc); } case OBD_IOC_LLOG_PRINT: @@ -2310,9 +2310,10 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, /* Below ioctls use obd_ioctl_data */ if (data->ioc_version != OBD_IOCTL_VERSION) { - CERROR("Bad magic %x != %x\n", data->ioc_version, - OBD_IOCTL_VERSION); - RETURN(-EINVAL); + CERROR("%s: iocontrol from '%s' bad magic %x != %x: rc = %d\n", + obd->obd_name, current->comm, + data->ioc_version, OBD_IOCTL_VERSION, rc); + RETURN(rc); } switch (cmd) { @@ -2335,7 +2336,8 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, barrier_exit(mdd->mdd_bottom); break; default: - rc = -ENOTTY; + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } RETURN(rc); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index ed538bf..3fe7a60 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -7527,14 +7527,16 @@ static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg) static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void __user *uarg) { - struct lu_env env; struct obd_device *obd = exp->exp_obd; struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); - struct dt_device *dt = mdt->mdt_bottom; + struct dt_device *dt = mdt->mdt_bottom; + struct lu_env env; int rc; ENTRY; - CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd); + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); + rc = lu_env_init(&env, LCT_MD_THREAD); if (rc) RETURN(rc); @@ -7552,14 +7554,12 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, struct obd_ioctl_data *data = karg; if (data->ioc_type & OBD_FLG_ABORT_RECOV_MDT) { - CERROR("%s: Aborting MDT recovery\n", - mdt_obd_name(mdt)); + CWARN("%s: Aborting MDT recovery\n", obd->obd_name); obd->obd_abort_mdt_recovery = 1; wake_up(&obd->obd_next_transno_waitq); } else { /* if (data->ioc_type & OBD_FLG_ABORT_RECOV_OST) */ /* lctl didn't set OBD_FLG_ABORT_RECOV_OST < 2.13.57 */ - CERROR("%s: Aborting client recovery\n", - mdt_obd_name(mdt)); + CWARN("%s: Aborting client recovery\n", obd->obd_name); obd->obd_abort_recovery = 1; target_stop_recovery_thread(obd); } @@ -7634,11 +7634,10 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, rc = llog_catalog_list(&env, mdt->mdt_bottom, 0, karg, &mti->mti_tmp_fid1); break; - } + } default: - rc = -EOPNOTSUPP; - CERROR("%s: Not supported cmd = %d, rc = %d\n", - mdt_obd_name(mdt), cmd, rc); + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } lu_env_fini(&env); diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index ea88f86..d1aba9f 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -986,80 +986,77 @@ out_pool: static int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void __user *uarg) { + struct obd_device *obd = exp->exp_obd; struct mgs_device *mgs = exp2mgs_dev(exp); - struct obd_ioctl_data *data = karg; + struct obd_ioctl_data *data = karg; struct lu_env env; - int rc = 0; + int rc = -EINVAL; - ENTRY; - CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd); + ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); rc = lu_env_init(&env, LCT_MG_THREAD); if (rc) RETURN(rc); - switch (cmd) { - + rc = -EINVAL; + switch (cmd) { case OBD_IOC_PARAM: { struct lustre_cfg *lcfg; if (data->ioc_type != LUSTRE_CFG_TYPE) { - CERROR("%s: unknown cfg record type: %d\n", - mgs->mgs_obd->obd_name, data->ioc_type); - GOTO(out, rc = -EINVAL); - } + CERROR("%s: unknown cfg record type '%x': rc = %d\n", + obd->obd_name, data->ioc_type, rc); + GOTO(out, rc); + } - OBD_ALLOC(lcfg, data->ioc_plen1); - if (lcfg == NULL) + OBD_ALLOC(lcfg, data->ioc_plen1); + if (lcfg == NULL) GOTO(out, rc = -ENOMEM); if (copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1)) - GOTO(out_free, rc = -EFAULT); + GOTO(out_free, rc = -EFAULT); - if (lcfg->lcfg_bufcount < 1) - GOTO(out_free, rc = -EINVAL); + if (lcfg->lcfg_bufcount < 1) + GOTO(out_free, rc); rc = mgs_set_param(&env, mgs, lcfg); if (rc) CERROR("%s: setparam err: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); out_free: - OBD_FREE(lcfg, data->ioc_plen1); + OBD_FREE(lcfg, data->ioc_plen1); break; - } - - case OBD_IOC_REPLACE_NIDS: { + } + case OBD_IOC_REPLACE_NIDS: if (!data->ioc_inllen1 || !data->ioc_inlbuf1) { - rc = -EINVAL; CERROR("%s: no device or fsname specified: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; } if (data->ioc_inllen1 > MTI_NAME_MAXLEN) { rc = -EOVERFLOW; CERROR("%s: device or fsname is too long: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; } if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) { - rc = -EINVAL; - CERROR("%s: device or fsname is not NUL terminated: " - "rc = %d\n", exp->exp_obd->obd_name, rc); + CERROR("%s: unterminated device or fsname: rc = %d\n", + obd->obd_name, rc); break; } if (!data->ioc_inllen2 || !data->ioc_inlbuf2) { - rc = -EINVAL; CERROR("%s: no NIDs specified: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; } if (data->ioc_inlbuf2[data->ioc_inllen2 - 1] != 0) { - rc = -EINVAL; - CERROR("%s: NID list is not NUL terminated: " - "rc = %d\n", exp->exp_obd->obd_name, rc); + CERROR("%s: NID list is not NUL terminated: rc = %d\n", + obd->obd_name, rc); break; } @@ -1068,30 +1065,26 @@ out_free: data->ioc_inlbuf2); if (rc) CERROR("%s: error replacing nids: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; - } - - case OBD_IOC_CLEAR_CONFIGS: { + case OBD_IOC_CLEAR_CONFIGS: if (!data->ioc_inllen1 || !data->ioc_inlbuf1) { - rc = -EINVAL; CERROR("%s: no device or fsname specified: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; } if (data->ioc_inllen1 > MTI_NAME_MAXLEN) { rc = -EOVERFLOW; CERROR("%s: device or fsname is too long: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; } if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) { - rc = -EINVAL; - CERROR("%s: device or fsname is not NUL terminated: " - "rc = %d\n", exp->exp_obd->obd_name, rc); + CERROR("%s: unterminated device or fsname: rc = %d\n", + obd->obd_name, rc); break; } @@ -1099,32 +1092,25 @@ out_free: rc = mgs_clear_configs(&env, mgs, data->ioc_inlbuf1); if (rc) CERROR("%s: error clearing config log: rc = %d\n", - exp->exp_obd->obd_name, rc); + obd->obd_name, rc); break; - } - case OBD_IOC_POOL: rc = mgs_iocontrol_pool(&env, mgs, data); break; - case OBD_IOC_BARRIER: rc = mgs_iocontrol_barrier(&env, mgs, data); break; - case OBD_IOC_NODEMAP: rc = mgs_iocontrol_nodemap(&env, mgs, data); break; - case OBD_IOC_LCFG_FORK: rc = mgs_lcfg_fork(&env, mgs, data->ioc_inlbuf1, data->ioc_inlbuf2); break; - case OBD_IOC_LCFG_ERASE: rc = mgs_lcfg_erase(&env, mgs, data->ioc_inlbuf1); break; - case OBD_IOC_CATLOGLIST: rc = mgs_list_logs(&env, mgs, data); break; @@ -1140,11 +1126,8 @@ out_free: llog_ctxt_put(ctxt); break; } - default: - CERROR("%s: unknown command %#x\n", - mgs->mgs_obd->obd_name, cmd); - rc = -ENOTTY; + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); break; } out: diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index c10a8da..b71f767 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -121,6 +121,29 @@ static struct notifier_block obdclass_oom = { .notifier_call = obdclass_oom_handler }; +int obd_ioctl_msg(const char *file, const char *func, int line, int level, + const char *name, unsigned int cmd, const char *msg, int rc) +{ + static struct cfs_debug_limit_state cdls; + char *dirs[] = { + [_IOC_NONE] = "_IO", + [_IOC_READ] = "_IOR", + [_IOC_WRITE] = "_IOW", + [_IOC_READ|_IOC_WRITE] = "_IOWR", + }; + char type; + + type = _IOC_TYPE(cmd); + __CDEBUG_WITH_LOC(file, func, line, level, &cdls, + "%s: iocontrol from '%s' cmd=%x %s('%c', %u, %u) %s: rc = %d\n", + name, current->comm, cmd, + dirs[_IOC_DIR(cmd)] ?: "_IO?", + isprint(type) ? type : '?', _IOC_NR(cmd), + _IOC_SIZE(cmd), msg, rc); + return rc; +} +EXPORT_SYMBOL(obd_ioctl_msg); + static int class_resolve_dev_name(__u32 len, const char *name) { int rc; @@ -235,26 +258,28 @@ int obd_ioctl_getdata(struct obd_ioctl_data **datap, int *len, void __user *arg) struct obd_ioctl_hdr hdr; struct obd_ioctl_data *data; int offset = 0; + int rc = -EINVAL; ENTRY; if (copy_from_user(&hdr, arg, sizeof(hdr))) RETURN(-EFAULT); if (hdr.ioc_version != OBD_IOCTL_VERSION) { - CERROR("Version mismatch kernel (%x) vs application (%x)\n", - OBD_IOCTL_VERSION, hdr.ioc_version); - RETURN(-EINVAL); + CERROR("%s: kernel/user version mismatch (%x != %x): rc = %d\n", + current->comm, OBD_IOCTL_VERSION, hdr.ioc_version, rc); + RETURN(rc); } if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) { - CERROR("User buffer len %d exceeds %d max buffer\n", - hdr.ioc_len, OBD_MAX_IOCTL_BUFFER); - RETURN(-EINVAL); + CERROR("%s: user buffer len %d exceeds %d max: rc = %d\n", + current->comm, hdr.ioc_len, OBD_MAX_IOCTL_BUFFER, rc); + RETURN(rc); } - if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) { - CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len); - RETURN(-EINVAL); + if (hdr.ioc_len < sizeof(*data)) { + CERROR("%s: user buffer %d too small for ioctl %zu: rc = %d\n", + current->comm, hdr.ioc_len, sizeof(*data), rc); + RETURN(rc); } /* When there are lots of processes calling vmalloc on multi-core @@ -264,9 +289,10 @@ int obd_ioctl_getdata(struct obd_ioctl_data **datap, int *len, void __user *arg) */ OBD_ALLOC_LARGE(data, hdr.ioc_len); if (!data) { - CERROR("Cannot allocate control buffer of len %d\n", - hdr.ioc_len); - RETURN(-EINVAL); + rc = -ENOMEM; + CERROR("%s: cannot allocate control buffer len %d: rc = %d\n", + current->comm, hdr.ioc_len, rc); + RETURN(rc); } *len = hdr.ioc_len; @@ -309,49 +335,52 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg) { struct obd_ioctl_data *data; struct obd_device *obd = NULL; - int err = 0, len = 0; + int rc, len = 0; ENTRY; - CDEBUG(D_IOCTL, "cmd = %x\n", cmd); - if (obd_ioctl_getdata(&data, &len, uarg)) { - CERROR("OBD ioctl: data error\n"); - RETURN(-EINVAL); + CDEBUG(D_IOCTL, "obdclass: cmd=%x len=%u uarg=%pK\n", cmd, len, uarg); + rc = obd_ioctl_getdata(&data, &len, uarg); + if (rc) { + CERROR("%s: ioctl data error: rc = %d\n", current->comm, rc); + RETURN(rc); } - switch (cmd) { - case OBD_IOC_PROCESS_CFG: { - struct lustre_cfg *lcfg; - - if (!data->ioc_plen1 || !data->ioc_pbuf1) { - CERROR("No config buffer passed!\n"); - GOTO(out, err = -EINVAL); - } - OBD_ALLOC(lcfg, data->ioc_plen1); - if (lcfg == NULL) - GOTO(out, err = -ENOMEM); - err = copy_from_user(lcfg, data->ioc_pbuf1, - data->ioc_plen1); - if (!err) - err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1); - if (!err) - err = class_process_config(lcfg); - - OBD_FREE(lcfg, data->ioc_plen1); - GOTO(out, err); - } + switch (cmd) { + case OBD_IOC_PROCESS_CFG: { + struct lustre_cfg *lcfg; + + if (!data->ioc_plen1 || !data->ioc_pbuf1) { + rc = OBD_IOC_ERROR("obdclass", cmd, "no config buffer", + -EINVAL); + GOTO(out, rc); + } + OBD_ALLOC(lcfg, data->ioc_plen1); + if (lcfg == NULL) + GOTO(out, rc = -ENOMEM); + rc = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1); + if (!rc) + rc = lustre_cfg_sanity_check(lcfg, data->ioc_plen1); + if (!rc) + rc = class_process_config(lcfg); + + OBD_FREE(lcfg, data->ioc_plen1); + GOTO(out, rc); + } #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0) case OBD_GET_VERSION: { static bool warned; if (!data->ioc_inlbuf1) { - CERROR("No buffer passed in ioctl\n"); - GOTO(out, err = -EINVAL); + rc = OBD_IOC_ERROR("obdclass", cmd, "no buffer passed", + -EINVAL); + GOTO(out, rc); } if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) { - CERROR("ioctl buffer too small to hold version\n"); - GOTO(out, err = -EINVAL); + rc = OBD_IOC_ERROR("obdclass", cmd, "buffer too small", + -EINVAL); + GOTO(out, rc); } if (!warned) { @@ -364,8 +393,8 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg) strlen(LUSTRE_VERSION_STRING) + 1); if (copy_to_user(uarg, data, len)) - err = -EFAULT; - GOTO(out, err); + rc = -EFAULT; + GOTO(out, rc); } #endif case OBD_IOC_NAME2DEV: { @@ -376,62 +405,64 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg) data->ioc_inlbuf1); data->ioc_dev = dev; if (dev < 0) - GOTO(out, err = -EINVAL); + GOTO(out, rc = -EINVAL); if (copy_to_user(uarg, data, sizeof(*data))) - err = -EFAULT; - GOTO(out, err); - } - - case OBD_IOC_UUID2DEV: { - /* Resolve a device uuid. This does not change the - * currently selected device. - */ - int dev; - struct obd_uuid uuid; - - if (!data->ioc_inllen1 || !data->ioc_inlbuf1) { - CERROR("No UUID passed!\n"); - GOTO(out, err = -EINVAL); - } - if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) { - CERROR("UUID not NUL terminated!\n"); - GOTO(out, err = -EINVAL); - } - - CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1); - obd_str2uuid(&uuid, data->ioc_inlbuf1); - dev = class_uuid2dev(&uuid); - data->ioc_dev = dev; - if (dev == -1) { - CDEBUG(D_IOCTL, "No device for UUID %s!\n", - data->ioc_inlbuf1); - GOTO(out, err = -EINVAL); - } + rc = -EFAULT; + GOTO(out, rc); + } + + case OBD_IOC_UUID2DEV: { + /* Resolve device uuid, does not change current selected dev */ + struct obd_uuid uuid; + int dev; + + if (!data->ioc_inllen1 || !data->ioc_inlbuf1) { + rc = OBD_IOC_ERROR("obdclass", cmd, "no UUID passed", + -EINVAL); + GOTO(out, rc); + } + if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) { + rc = OBD_IOC_ERROR("obdclass", cmd, "unterminated UUID", + -EINVAL); + GOTO(out, rc); + } + + CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1); + obd_str2uuid(&uuid, data->ioc_inlbuf1); + dev = class_uuid2dev(&uuid); + data->ioc_dev = dev; + if (dev == -1) { + CDEBUG(D_IOCTL, "No device for UUID %s!\n", + data->ioc_inlbuf1); + GOTO(out, rc = -EINVAL); + } CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1, dev); if (copy_to_user(uarg, data, sizeof(*data))) - err = -EFAULT; - GOTO(out, err); + rc = -EFAULT; + GOTO(out, rc); } - case OBD_IOC_GETDEVICE: { - int index = data->ioc_count; - char *status, *str; + case OBD_IOC_GETDEVICE: { + int index = data->ioc_count; + char *status, *str; - if (!data->ioc_inlbuf1) { - CERROR("No buffer passed in ioctl\n"); - GOTO(out, err = -EINVAL); - } - if (data->ioc_inllen1 < 128) { - CERROR("ioctl buffer too small to hold version\n"); - GOTO(out, err = -EINVAL); - } + if (!data->ioc_inlbuf1) { + rc = OBD_IOC_ERROR("obdclass", cmd, "no buffer passed", + -EINVAL); + GOTO(out, rc); + } + if (data->ioc_inllen1 < 128) { + rc = OBD_IOC_ERROR("obdclass", cmd, "too small version", + -EINVAL); + GOTO(out, rc); + } - obd = class_num2obd(index); - if (!obd) - GOTO(out, err = -ENOENT); + obd = class_num2obd(index); + if (!obd) + GOTO(out, rc = -ENOENT); if (obd->obd_stopping) status = "ST"; @@ -451,45 +482,48 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg) atomic_read(&obd->obd_refcount)); if (copy_to_user(uarg, data, len)) - err = -EFAULT; + rc = -EFAULT; - GOTO(out, err); + GOTO(out, rc); } } - 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); - } + if (data->ioc_dev == OBD_DEV_BY_DEVNAME) { + if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL) + GOTO(out, rc = -EINVAL); + if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME) + GOTO(out, rc = -EINVAL); + obd = class_name2obd(data->ioc_inlbuf4); + } else if (data->ioc_dev < class_devno_max()) { + obd = class_num2obd(data->ioc_dev); + } else { + rc = OBD_IOC_ERROR("obdclass", cmd, "no device", -EINVAL); + GOTO(out, rc); + } - if (obd == NULL) { - CERROR("OBD ioctl : No Device %d\n", data->ioc_dev); - GOTO(out, err = -EINVAL); - } - LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); + if (obd == NULL) { + rc = OBD_IOC_ERROR(data->ioc_inlbuf4, cmd, "no device found", + -EINVAL); + GOTO(out, rc); + } + LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); - if (!obd->obd_set_up || obd->obd_stopping) { - CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev); - GOTO(out, err = -EINVAL); - } + if (!obd->obd_set_up || obd->obd_stopping) { + rc = -EINVAL; + CERROR("obdclass: device %d not set up: rc = %d\n", + data->ioc_dev, rc); + GOTO(out, rc); + } - err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL); - if (err) - GOTO(out, err); + rc = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL); + if (rc) + GOTO(out, rc); if (copy_to_user(uarg, data, len)) - err = -EFAULT; + rc = -EFAULT; out: OBD_FREE_LARGE(data, len); - RETURN(err); + RETURN(rc); } /* class_handle_ioctl */ /* to control /dev/obd */ @@ -501,10 +535,10 @@ static long obd_class_ioctl(struct file *filp, unsigned int cmd, ENTRY; /* Allow non-root access for some limited ioctls */ if (!capable(CAP_SYS_ADMIN)) - RETURN(err = -EACCES); + RETURN(-EACCES); if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */ - RETURN(err = -ENOTTY); + RETURN(-ENOTTY); err = class_handle_ioctl(cmd, (void __user *)arg); diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 002bc6e..d6bc42e 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -2260,20 +2260,23 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, #ifdef HAVE_SERVER_SUPPORT struct tgt_session_info *tsi; #endif - struct obd_device *obd = exp->exp_obd; - struct echo_device *ed = obd2echo_dev(obd); + struct obd_device *obd = exp->exp_obd; + struct echo_device *ed = obd2echo_dev(obd); struct echo_client_obd *ec = ed->ed_ec; - struct echo_object *eco; - struct obd_ioctl_data *data = karg; - struct lu_env *env; - unsigned long env_tags = 0; - __u16 refcheck; - struct obdo *oa; - struct lu_fid fid; - int rw = OBD_BRW_READ; - int rc = 0; + struct echo_object *eco; + struct obd_ioctl_data *data = karg; + struct lu_env *env; + unsigned long env_tags = 0; + __u16 refcheck; + struct obdo *oa; + struct lu_fid fid; + int rw = OBD_BRW_READ; + int rc = -EINVAL; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + exp->exp_obd->obd_name, cmd, len, karg, uarg); + oa = &data->ioc_obdo1; if (!(oa->o_valid & OBD_MD_FLGROUP)) { oa->o_valid |= OBD_MD_FLGROUP; @@ -2411,10 +2414,9 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, case OBD_IOC_BRW_READ: rc = echo_client_brw_ioctl(env, rw, exp, data); GOTO(out, rc); - default: - CERROR("echo_ioctl(): unrecognised ioctl %#x\n", cmd); - GOTO(out, rc = -ENOTTY); + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } EXIT; diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index 166cee3..aa538f6 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -1257,15 +1257,15 @@ static int ofd_iocontrol(unsigned int cmd, struct obd_export *exp, int len, int rc; ENTRY; - - CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd); + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); rc = lu_env_init(&env, LCT_DT_THREAD); if (rc) RETURN(rc); switch (cmd) { case OBD_IOC_ABORT_RECOVERY: - CERROR("%s: aborting recovery\n", obd->obd_name); + CWARN("%s: Aborting recovery\n", obd->obd_name); obd->obd_abort_recovery = 1; target_stop_recovery_thread(obd); break; @@ -1302,7 +1302,7 @@ static int ofd_iocontrol(unsigned int cmd, struct obd_export *exp, int len, stop.ls_flags = 0; else stop.ls_flags = - ((struct lfsck_stop *)(data->ioc_inlbuf1))->ls_flags; + ((struct lfsck_stop *)(data->ioc_inlbuf1))->ls_flags; rc = lfsck_stop(&env, ofd->ofd_osd, &stop); break; @@ -1311,8 +1311,8 @@ static int ofd_iocontrol(unsigned int cmd, struct obd_export *exp, int len, rc = ofd_ioc_get_obj_version(&env, ofd, karg); break; default: - CERROR("%s: not supported cmd = %#x\n", obd->obd_name, cmd); - rc = -ENOTTY; + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } lu_env_fini(&env); diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 08a286d..4b96bec 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -3334,6 +3334,9 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, int rc = 0; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + obd->obd_name, cmd, len, karg, uarg); + if (!try_module_get(THIS_MODULE)) { CERROR("%s: cannot get module '%s'\n", obd->obd_name, module_name(THIS_MODULE)); @@ -3354,9 +3357,8 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, data->ioc_offset); break; default: - rc = -ENOTTY; - CDEBUG(D_INODE, "%s: unrecognised ioctl %#x by %s: rc = %d\n", - obd->obd_name, cmd, current->comm, rc); + rc = OBD_IOC_DEBUG(D_IOCTL, obd->obd_name, cmd, "unrecognized", + -ENOTTY); break; } diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index d1232e9..3566877 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -1667,12 +1667,14 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp, static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void __user *uarg) { - struct obd_device *obd = exp->exp_obd; - struct osp_device *d; - struct obd_ioctl_data *data = karg; - int rc = 0; + struct obd_device *obd = exp->exp_obd; + struct osp_device *d; + struct obd_ioctl_data *data = karg; + int rc = -EINVAL; ENTRY; + CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n", + exp->exp_obd->obd_name, cmd, len, karg, uarg); LASSERT(obd->obd_lu_dev); d = lu2osp_dev(obd->obd_lu_dev); @@ -1696,15 +1698,13 @@ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len, data->ioc_offset); break; default: - CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name, - cmd, current->comm); - rc = -ENOTTY; + rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY); + break; } module_put(THIS_MODULE); return rc; } - /** * Implementation of obd_ops::o_get_info *