From d5be104cc9b0c7a71b30aa5feb16873aa30803a9 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Thu, 11 Apr 2019 08:40:23 +0800 Subject: [PATCH 1/1] LU-11355 lustre: enable fstrim on lustre device pass the FITRIM ioctl through the OST/MDT mountpoint to the underlying filesystem, which allows us to run fstrim on server mount point directly. Change-Id: Ia6f9b43e48245ee7907a47f05c3924b3640bc734 Signed-off-by: Andreas Dilger Signed-off-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/33131 Reviewed-by: Li Xi Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Tested-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/dt_object.h | 17 +++++++++++++++ lustre/obdclass/obd_mount_server.c | 42 ++++++++++++++++++++++++++++++++++++++ lustre/osd-ldiskfs/osd_handler.c | 6 ++++++ 3 files changed, 65 insertions(+) diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index aa8a65b..7c4f4e3 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -254,6 +254,13 @@ struct dt_device_operations { struct dt_device_param *param); /** + * Return device's super block. + * + * \param[in] dev dt device + */ + struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev); + + /** * Sync the device. * * Sync all the cached state (dirty buffers, pages, etc) to the @@ -2534,6 +2541,16 @@ static inline void dt_conf_get(const struct lu_env *env, return dev->dd_ops->dt_conf_get(env, dev, param); } +static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev) +{ + LASSERT(dev); + LASSERT(dev->dd_ops); + if (dev->dd_ops->dt_mnt_sb_get) + return dev->dd_ops->dt_mnt_sb_get(dev); + + return ERR_PTR(-EOPNOTSUPP); +} + static inline int dt_sync(const struct lu_env *env, struct dt_device *dev) { LASSERT(dev); diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index 92cf5cc..42af490 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -1769,6 +1769,43 @@ static ssize_t lustre_listxattr(struct dentry *d_entry, char *name, return -EOPNOTSUPP; } +static bool is_cmd_supported(unsigned int command) +{ + switch (command) { + case FITRIM: + return true; + default: + return false; + } + + return false; +} + +static long server_ioctl(struct file *filp, unsigned int command, + unsigned long arg) +{ + struct file active_filp; + struct inode *inode = file_inode(filp); + struct lustre_sb_info *lsi = s2lsi(inode->i_sb); + struct super_block *dd_sb = dt_mnt_sb_get(lsi->lsi_dt_dev); + struct inode *active_inode; + int err = -EOPNOTSUPP; + + if (IS_ERR(dd_sb) || !is_cmd_supported(command)) + return err; + + active_inode = igrab(dd_sb->s_root->d_inode); + if (!active_inode) + return -EACCES; + + active_filp.f_inode = active_inode; + if (active_inode->i_fop && active_inode->i_fop->unlocked_ioctl) + err = active_inode->i_fop->unlocked_ioctl(&active_filp, + command, arg); + iput(active_inode); + return err; +} + static const struct inode_operations server_inode_operations = { #ifdef HAVE_IOP_XATTR .setxattr = lustre_setxattr, @@ -1777,6 +1814,10 @@ static const struct inode_operations server_inode_operations = { .listxattr = lustre_listxattr, }; +static const struct file_operations server_file_operations = { + .unlocked_ioctl = server_ioctl, +}; + #define log2(n) ffz(~(n)) #define LUSTRE_SUPER_MAGIC 0x0BD00BD1 @@ -1805,6 +1846,7 @@ static int server_fill_super_common(struct super_block *sb) /* apparently we need to be a directory for the mount to finish */ root->i_mode = S_IFDIR; root->i_op = &server_inode_operations; + root->i_fop = &server_file_operations; sb->s_root = d_make_root(root); if (!sb->s_root) { CERROR("%s: can't make root dentry\n", sb->s_id); diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index ea81256..b28dd17 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2360,6 +2360,11 @@ static void osd_conf_get(const struct lu_env *env, } } +static struct super_block *osd_mnt_sb_get(const struct dt_device *d) +{ + return osd_sb(osd_dt_dev(d)); +} + /* * Concurrency: shouldn't matter. */ @@ -2522,6 +2527,7 @@ static const struct dt_device_operations osd_dt_ops = { .dt_trans_stop = osd_trans_stop, .dt_trans_cb_add = osd_trans_cb_add, .dt_conf_get = osd_conf_get, + .dt_mnt_sb_get = osd_mnt_sb_get, .dt_sync = osd_sync, .dt_ro = osd_ro, .dt_commit_async = osd_commit_async, -- 1.8.3.1