From 770f9c0e7e8eb3dc3a9e531210cbf29008e9a27d Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 27 Jul 2011 01:54:20 -0600 Subject: [PATCH] LU-540 quota: move quota ioctl handling to helper The ll_dir_ioctl()::OBD_IOC_QUOTACTL handling is very large, and is moved to a helper routine quotactl_ioctl() instead of being inline. This will also facilitate the compatibility handling for the 1.x QUOTACTL ioctl handling, by being able to share quotactl_ioctl() code. Also, check for LL_IOC_QUOTACTL in ll_dir_ioctl(), since this is the ioctl() number exported to userspace, and it also facilitates being able to find the kernel-side ioctl handler for llapi_quotactl(). Add comments to show the duplicate user/kernel ioctl definitions. Keep these separate for now, to allow the kernel/userspace values to be defined differently for compatibility reasons. There should be no functional differences with this change. Change-Id: Iecfaf20ddbd78d77a546e1ba5a60b281732a85d9 Signed-off-by: Andreas Dilger Reviewed-on: http://review.whamcloud.com/1151 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Johann Lombardi Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- lustre/include/lustre/lustre_user.h | 10 +- lustre/include/lustre_lib.h | 10 +- lustre/llite/dir.c | 196 ++++++++++++++++++------------------ 3 files changed, 116 insertions(+), 100 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 736254b..7a8faf0 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -115,19 +115,25 @@ struct obd_statfs { * *STRIPE* - set/get lov_user_md * *INFO - set/get lov_user_mds_data */ -/* see for ioctl numberss 101-150 */ +/* see for ioctl numberss 101-150 */ #define LL_IOC_GETFLAGS _IOR ('f', 151, long) #define LL_IOC_SETFLAGS _IOW ('f', 152, long) #define LL_IOC_CLRFLAGS _IOW ('f', 153, long) +/* LL_IOC_LOV_SETSTRIPE: See also OBD_IOC_LOV_SETSTRIPE */ #define LL_IOC_LOV_SETSTRIPE _IOW ('f', 154, long) +/* LL_IOC_LOV_GETSTRIPE: See also OBD_IOC_LOV_GETSTRIPE */ #define LL_IOC_LOV_GETSTRIPE _IOW ('f', 155, long) +/* LL_IOC_LOV_SETEA: See also OBD_IOC_LOV_SETEA */ #define LL_IOC_LOV_SETEA _IOW ('f', 156, long) #define LL_IOC_RECREATE_OBJ _IOW ('f', 157, long) #define LL_IOC_RECREATE_FID _IOW ('f', 157, struct lu_fid) #define LL_IOC_GROUP_LOCK _IOW ('f', 158, long) #define LL_IOC_GROUP_UNLOCK _IOW ('f', 159, long) +/* LL_IOC_QUOTACHECK: See also OBD_IOC_QUOTACHECK */ #define LL_IOC_QUOTACHECK _IOW ('f', 160, int) +/* LL_IOC_POLL_QUOTACHECK: See also OBD_IOC_POLL_QUOTACHECK */ #define LL_IOC_POLL_QUOTACHECK _IOR ('f', 161, struct if_quotacheck *) +/* LL_IOC_QUOTACTL: See also OBD_IOC_QUOTACTL */ #define LL_IOC_QUOTACTL _IOWR('f', 162, struct if_quotactl *) #define IOC_OBD_STATFS _IOWR('f', 164, struct obd_statfs *) #define IOC_LOV_GETINFO _IOWR('f', 165, struct lov_user_mds_data *) @@ -142,7 +148,7 @@ struct obd_statfs { #define LL_IOC_GET_CONNECT_FLAGS _IOWR('f', 174, __u64 *) #define LL_IOC_GET_MDTIDX _IOR ('f', 175, int) #define LL_IOC_HSM_CT_START _IOW ('f', 176,struct lustre_kernelcomm) -/* see for ioctl numbers 177-210 */ +/* see for ioctl numbers 177-210 */ #define LL_STATFS_MDC 1 diff --git a/lustre/include/lustre_lib.h b/lustre/include/lustre_lib.h index 6dd1a67..456dee9 100644 --- a/lustre/include/lustre_lib.h +++ b/lustre/include/lustre_lib.h @@ -494,15 +494,21 @@ static inline void obd_ioctl_freedata(char *buf, int len) #define 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) -/* see for ioctls 151-153 */ +/* see also for ioctls 151-153 */ +/* OBD_IOC_LOV_SETSTRIPE: See also LL_IOC_LOV_SETSTRIPE */ #define OBD_IOC_LOV_SETSTRIPE _IOW ('f', 154, OBD_IOC_DATA_TYPE) +/* OBD_IOC_LOV_GETSTRIPE: See also LL_IOC_LOV_GETSTRIPE */ #define OBD_IOC_LOV_GETSTRIPE _IOW ('f', 155, OBD_IOC_DATA_TYPE) +/* OBD_IOC_LOV_SETEA: See also LL_IOC_LOV_SETEA */ #define OBD_IOC_LOV_SETEA _IOW ('f', 156, OBD_IOC_DATA_TYPE) /* see for ioctls 157-159 */ +/* OBD_IOC_QUOTACHECK: See also LL_IOC_QUOTACHECK */ #define OBD_IOC_QUOTACHECK _IOW ('f', 160, int) +/* OBD_IOC_POLL_QUOTACHECK: See also LL_IOC_POLL_QUOTACHECK */ #define OBD_IOC_POLL_QUOTACHECK _IOR ('f', 161, struct if_quotacheck *) +/* OBD_IOC_QUOTACTL: See also LL_IOC_QUOTACTL */ #define OBD_IOC_QUOTACTL _IOWR('f', 162, struct if_quotactl *) -/* see for ioctls 163-175 */ +/* see also for ioctls 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) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 7466dd8..436e77e 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -738,7 +738,7 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump, lum_size = sizeof(struct lov_user_md_v3); break; } - default: { + default: { CDEBUG(D_IOCTL, "bad userland LOV MAGIC:" " %#08x != %#08x nor %#08x\n", lump->lmm_magic, LOV_USER_MAGIC_V1, @@ -916,6 +916,102 @@ static int copy_and_ioctl(int cmd, struct obd_export *exp, void *data, int len) return rc; } +static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl) +{ + int cmd = qctl->qc_cmd; + int type = qctl->qc_type; + int id = qctl->qc_id; + int valid = qctl->qc_valid; + int rc = 0; + ENTRY; + + switch (cmd) { + case LUSTRE_Q_INVALIDATE: + case LUSTRE_Q_FINVALIDATE: + case Q_QUOTAON: + case Q_QUOTAOFF: + case Q_SETQUOTA: + case Q_SETINFO: + if (!cfs_capable(CFS_CAP_SYS_ADMIN) || + sbi->ll_flags & LL_SBI_RMT_CLIENT) + RETURN(-EPERM); + break; + case Q_GETQUOTA: + if (((type == USRQUOTA && cfs_curproc_euid() != id) || + (type == GRPQUOTA && !in_egroup_p(id))) && + (!cfs_capable(CFS_CAP_SYS_ADMIN) || + sbi->ll_flags & LL_SBI_RMT_CLIENT)) + RETURN(-EPERM); + break; + case Q_GETINFO: + break; + default: + CERROR("unsupported quotactl op: %#x\n", cmd); + RETURN(-ENOTTY); + } + + if (valid != QC_GENERAL) { + if (sbi->ll_flags & LL_SBI_RMT_CLIENT) + RETURN(-EOPNOTSUPP); + + if (cmd == Q_GETINFO) + qctl->qc_cmd = Q_GETOINFO; + else if (cmd == Q_GETQUOTA) + qctl->qc_cmd = Q_GETOQUOTA; + else + RETURN(-EINVAL); + + switch (valid) { + case QC_MDTIDX: + rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp, + sizeof(*qctl), qctl, NULL); + break; + case QC_OSTIDX: + rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp, + sizeof(*qctl), qctl, NULL); + break; + case QC_UUID: + rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp, + sizeof(*qctl), qctl, NULL); + if (rc == -EAGAIN) + rc = obd_iocontrol(OBD_IOC_QUOTACTL, + sbi->ll_dt_exp, + sizeof(*qctl), qctl, NULL); + break; + default: + rc = -EINVAL; + break; + } + + if (rc) + RETURN(rc); + + qctl->qc_cmd = cmd; + } else { + struct obd_quotactl *oqctl; + + OBD_ALLOC_PTR(oqctl); + if (oqctl == NULL) + RETURN(-ENOMEM); + + QCTL_COPY(oqctl, qctl); + rc = obd_quotactl(sbi->ll_md_exp, oqctl); + if (rc) { + if (rc != -EALREADY && cmd == Q_QUOTAON) { + oqctl->qc_cmd = Q_QUOTAOFF; + obd_quotactl(sbi->ll_md_exp, oqctl); + } + OBD_FREE_PTR(oqctl); + RETURN(rc); + } + + QCTL_COPY(qctl, oqctl); + OBD_FREE_PTR(oqctl); + } + + RETURN(rc); +} + static int ll_dir_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { @@ -1287,9 +1383,8 @@ out_free: OBD_FREE_PTR(check); RETURN(rc); } - case OBD_IOC_QUOTACTL: { + case LL_IOC_QUOTACTL: { struct if_quotactl *qctl; - int cmd, type, id, valid; OBD_ALLOC_PTR(qctl); if (!qctl) @@ -1298,100 +1393,9 @@ out_free: if (cfs_copy_from_user(qctl, (void *)arg, sizeof(*qctl))) GOTO(out_quotactl, rc = -EFAULT); - cmd = qctl->qc_cmd; - type = qctl->qc_type; - id = qctl->qc_id; - valid = qctl->qc_valid; - - switch (cmd) { - case LUSTRE_Q_INVALIDATE: - case LUSTRE_Q_FINVALIDATE: - case Q_QUOTAON: - case Q_QUOTAOFF: - case Q_SETQUOTA: - case Q_SETINFO: - if (!cfs_capable(CFS_CAP_SYS_ADMIN) || - sbi->ll_flags & LL_SBI_RMT_CLIENT) - GOTO(out_quotactl, rc = -EPERM); - break; - case Q_GETQUOTA: - if (((type == USRQUOTA && cfs_curproc_euid() != id) || - (type == GRPQUOTA && !in_egroup_p(id))) && - (!cfs_capable(CFS_CAP_SYS_ADMIN) || - sbi->ll_flags & LL_SBI_RMT_CLIENT)) - GOTO(out_quotactl, rc = -EPERM); - break; - case Q_GETINFO: - break; - default: - CERROR("unsupported quotactl op: %#x\n", cmd); - GOTO(out_quotactl, rc = -ENOTTY); - } - - if (valid != QC_GENERAL) { - if (sbi->ll_flags & LL_SBI_RMT_CLIENT) - GOTO(out_quotactl, rc = -EOPNOTSUPP); - - if (cmd == Q_GETINFO) - qctl->qc_cmd = Q_GETOINFO; - else if (cmd == Q_GETQUOTA) - qctl->qc_cmd = Q_GETOQUOTA; - else - GOTO(out_quotactl, rc = -EINVAL); - - switch (valid) { - case QC_MDTIDX: - rc = obd_iocontrol(OBD_IOC_QUOTACTL, - sbi->ll_md_exp, - sizeof(*qctl), qctl, NULL); - break; - case QC_OSTIDX: - rc = obd_iocontrol(OBD_IOC_QUOTACTL, - sbi->ll_dt_exp, - sizeof(*qctl), qctl, NULL); - break; - case QC_UUID: - rc = obd_iocontrol(OBD_IOC_QUOTACTL, - sbi->ll_md_exp, - sizeof(*qctl), qctl, NULL); - if (rc == -EAGAIN) - rc = obd_iocontrol(OBD_IOC_QUOTACTL, - sbi->ll_dt_exp, - sizeof(*qctl), qctl, - NULL); - break; - default: - rc = -EINVAL; - break; - } - - if (rc) - GOTO(out_quotactl, rc); - else - qctl->qc_cmd = cmd; - } else { - struct obd_quotactl *oqctl; - - OBD_ALLOC_PTR(oqctl); - if (!oqctl) - GOTO(out_quotactl, rc = -ENOMEM); - - QCTL_COPY(oqctl, qctl); - rc = obd_quotactl(sbi->ll_md_exp, oqctl); - if (rc) { - if (rc != -EALREADY && cmd == Q_QUOTAON) { - oqctl->qc_cmd = Q_QUOTAOFF; - obd_quotactl(sbi->ll_md_exp, oqctl); - } - OBD_FREE_PTR(oqctl); - GOTO(out_quotactl, rc); - } else { - QCTL_COPY(qctl, oqctl); - OBD_FREE_PTR(oqctl); - } - } + rc = quotactl_ioctl(sbi, qctl); - if (cfs_copy_to_user((void *)arg, qctl, sizeof(*qctl))) + if (rc == 0 && cfs_copy_to_user((void *)arg,qctl,sizeof(*qctl))) rc = -EFAULT; out_quotactl: -- 1.8.3.1