From 7dae2c81e7b2e68a596c5b431444be0fae308156 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 2 May 2017 09:46:18 -0700 Subject: Linux 4.12 compat: super_setup_bdi_name() All filesystems were converted to dynamically allocated BDIs. The destruction of backing_dev_info structures is handled as part of super block destruction. Refactor the code to abstract away the details of creating and destroying a BDI. Reviewed-by: Chunwei Chen Signed-off-by: Brian Behlendorf Closes #6089 --- include/linux/vfs_compat.h | 87 +++++++++++++++++++++++++++++++++++++++++----- include/sys/zfs_vfsops.h | 1 - 2 files changed, 78 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/linux/vfs_compat.h b/include/linux/vfs_compat.h index cd22b522a..4e61b1d09 100644 --- a/include/linux/vfs_compat.h +++ b/include/linux/vfs_compat.h @@ -70,45 +70,114 @@ truncate_setsize(struct inode *ip, loff_t new) /* * 2.6.32 - 2.6.33, bdi_setup_and_register() is not available. * 2.6.34 - 3.19, bdi_setup_and_register() takes 3 arguments. - * 4.0 - x.y, bdi_setup_and_register() takes 2 arguments. + * 4.0 - 4.11, bdi_setup_and_register() takes 2 arguments. + * 4.12 - x.y, super_setup_bdi_name() new interface. */ -#if defined(HAVE_2ARGS_BDI_SETUP_AND_REGISTER) +#if defined(HAVE_SUPER_SETUP_BDI_NAME) static inline int -zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name) +zpl_bdi_setup(struct super_block *sb, char *name) { - return (bdi_setup_and_register(bdi, name)); + return (super_setup_bdi_name(sb, name)); +} +static inline void +zpl_bdi_destroy(struct super_block *sb) +{ +} +#elif defined(HAVE_2ARGS_BDI_SETUP_AND_REGISTER) +static inline int +zpl_bdi_setup(struct super_block *sb, char *name) +{ + struct backing_dev_info *bdi; + int error; + + bdi = kmem_zalloc(sizeof (struct backing_dev_info), KM_SLEEP); + error = bdi_setup_and_register(bdi, name); + if (error) { + kmem_free(bdi, sizeof (struct backing_dev_info)); + return (error); + } + + sb->s_bdi = bdi; + + return (0); +} +static inline void +zpl_bdi_destroy(struct super_block *sb) +{ + struct backing_dev_info *bdi = sb->s_bdi; + + bdi_destroy(bdi); + kmem_free(bdi, sizeof (struct backing_dev_info)); + sb->s_bdi = NULL; } #elif defined(HAVE_3ARGS_BDI_SETUP_AND_REGISTER) static inline int -zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name) +zpl_bdi_setup(struct super_block *sb, char *name) { - return (bdi_setup_and_register(bdi, name, BDI_CAP_MAP_COPY)); + struct backing_dev_info *bdi; + int error; + + bdi = kmem_zalloc(sizeof (struct backing_dev_info), KM_SLEEP); + error = bdi_setup_and_register(bdi, name, BDI_CAP_MAP_COPY); + if (error) { + kmem_free(sb->s_bdi, sizeof (struct backing_dev_info)); + return (error); + } + + sb->s_bdi = bdi; + + return (0); +} +static inline void +zpl_bdi_destroy(struct super_block *sb) +{ + struct backing_dev_info *bdi = sb->s_bdi; + + bdi_destroy(bdi); + kmem_free(bdi, sizeof (struct backing_dev_info)); + sb->s_bdi = NULL; } #else extern atomic_long_t zfs_bdi_seq; static inline int -zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name) +zpl_bdi_setup(struct super_block *sb, char *name) { + struct backing_dev_info *bdi; char tmp[32]; int error; + bdi = kmem_zalloc(sizeof (struct backing_dev_info), KM_SLEEP); bdi->name = name; bdi->capabilities = BDI_CAP_MAP_COPY; error = bdi_init(bdi); - if (error) + if (error) { + kmem_free(bdi, sizeof (struct backing_dev_info)); return (error); + } sprintf(tmp, "%.28s%s", name, "-%d"); error = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&zfs_bdi_seq)); if (error) { bdi_destroy(bdi); + kmem_free(bdi, sizeof (struct backing_dev_info)); return (error); } - return (error); + sb->s_bdi = bdi; + + return (0); +} +static inline void +zpl_bdi_destroy(struct super_block *sb) +{ + struct backing_dev_info *bdi = sb->s_bdi; + + bdi_destroy(bdi); + kmem_free(bdi, sizeof (struct backing_dev_info)); + sb->s_bdi = NULL; } #endif diff --git a/include/sys/zfs_vfsops.h b/include/sys/zfs_vfsops.h index aeecc472d..2326da422 100644 --- a/include/sys/zfs_vfsops.h +++ b/include/sys/zfs_vfsops.h @@ -75,7 +75,6 @@ typedef struct zfs_mnt { struct zfsvfs { vfs_t *z_vfs; /* generic fs struct */ struct super_block *z_sb; /* generic super_block */ - struct backing_dev_info z_bdi; /* generic backing dev info */ struct zfsvfs *z_parent; /* parent fs */ objset_t *z_os; /* objset reference */ uint64_t z_flags; /* super_block flags */ -- cgit v1.2.3