From 140b9e6d736a8c11d660094fc11ee61a89264b13 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Thu, 16 Jul 2020 13:49:36 +1000 Subject: [PATCH] LU-6142 lustre: change super/file/inode operations to const All 'struct file_operations', 'struct inode_operations', 'struct export_operations' and 'struct super_operations' are changed to 'const'. This potenetially allows them to be placed in read-only memory, and ensure they are never changed. Test-Parameters: trivial Signed-off-by: Mr NeilBrown Change-Id: I8b236f0248eca11f91f11da02fe18be3f6d2e17c Reviewed-on: https://review.whamcloud.com/39394 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Andreas Dilger --- lnet/klnds/gnilnd/gnilnd_proc.c | 48 ++++++++++++++++---------------- lustre/llite/file.c | 8 +++--- lustre/llite/llite_internal.h | 56 +++++++++++++++++++------------------- lustre/llite/llite_nfs.c | 2 +- lustre/llite/super25.c | 2 +- lustre/llite/symlink.c | 2 +- lustre/lod/lod_pool.c | 2 +- lustre/lov/lov_pool.c | 10 +++---- lustre/obdclass/class_obd.c | 2 +- lustre/obdclass/lu_ref.c | 12 ++++---- lustre/obdclass/obd_mount_server.c | 2 +- lustre/ptlrpc/lproc_ptlrpc.c | 16 +++++------ lustre/quota/lproc_quota.c | 2 +- lustre/quota/lquota_internal.h | 2 +- 14 files changed, 83 insertions(+), 83 deletions(-) diff --git a/lnet/klnds/gnilnd/gnilnd_proc.c b/lnet/klnds/gnilnd/gnilnd_proc.c index dfb01f5..fc806dc 100644 --- a/lnet/klnds/gnilnd/gnilnd_proc.c +++ b/lnet/klnds/gnilnd/gnilnd_proc.c @@ -523,12 +523,12 @@ kgnilnd_mdd_seq_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations kgn_mdd_fops = { - .owner = THIS_MODULE, - .open = kgnilnd_mdd_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct file_operations kgn_mdd_fops = { + .owner = THIS_MODULE, + .open = kgnilnd_mdd_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; typedef struct { @@ -735,12 +735,12 @@ kgnilnd_smsg_seq_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations kgn_smsg_fops = { - .owner = THIS_MODULE, - .open = kgnilnd_smsg_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct file_operations kgn_smsg_fops = { + .owner = THIS_MODULE, + .open = kgnilnd_smsg_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; typedef struct { @@ -1088,12 +1088,12 @@ kgnilnd_conn_seq_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations kgn_conn_fops = { - .owner = THIS_MODULE, - .open = kgnilnd_conn_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct file_operations kgn_conn_fops = { + .owner = THIS_MODULE, + .open = kgnilnd_conn_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; typedef struct { @@ -1310,12 +1310,12 @@ kgnilnd_peer_seq_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations kgn_peer_fops = { - .owner = THIS_MODULE, - .open = kgnilnd_peer_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +static const struct file_operations kgn_peer_fops = { + .owner = THIS_MODULE, + .open = kgnilnd_peer_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; static struct proc_dir_entry *kgn_proc_root; diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 540bd2f..114beb2 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -5315,7 +5315,7 @@ int ll_inode_permission(struct inode *inode, int mask) } /* -o localflock - only provides locally consistent flock locks */ -struct file_operations ll_file_operations = { +const struct file_operations ll_file_operations = { #ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER # ifdef HAVE_SYNC_READ_WRITE .read = new_sync_read, @@ -5344,7 +5344,7 @@ struct file_operations ll_file_operations = { .fallocate = ll_fallocate, }; -struct file_operations ll_file_operations_flock = { +const struct file_operations ll_file_operations_flock = { #ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER # ifdef HAVE_SYNC_READ_WRITE .read = new_sync_read, @@ -5376,7 +5376,7 @@ struct file_operations ll_file_operations_flock = { }; /* These are for -o noflock - to return ENOSYS on flock calls */ -struct file_operations ll_file_operations_noflock = { +const struct file_operations ll_file_operations_noflock = { #ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER # ifdef HAVE_SYNC_READ_WRITE .read = new_sync_read, @@ -5407,7 +5407,7 @@ struct file_operations ll_file_operations_noflock = { .fallocate = ll_fallocate, }; -struct inode_operations ll_file_inode_operations = { +const struct inode_operations ll_file_inode_operations = { .setattr = ll_setattr, .getattr = ll_getattr, .permission = ll_inode_permission, diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index e5083c6..480d55e 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -718,15 +718,15 @@ struct ll_sb_info { struct dentry *ll_debugfs_entry; struct lu_fid ll_root_fid; /* root object fid */ - int ll_flags; + int ll_flags; unsigned int ll_xattr_cache_enabled:1, ll_xattr_cache_set:1, /* already set to 0/1 */ ll_client_common_fill_super_succeeded:1, ll_checksum_set:1; - struct lustre_client_ocd ll_lco; + struct lustre_client_ocd ll_lco; - struct lprocfs_stats *ll_stats; /* lprocfs stats counter */ + struct lprocfs_stats *ll_stats; /* lprocfs stats counter */ /* Used to track "unstable" pages on a client, and maintain a * LRU list of clean pages. An "unstable" page is defined as @@ -734,24 +734,24 @@ struct ll_sb_info { * but is uncommitted to stable storage. */ struct cl_client_cache *ll_cache; - struct lprocfs_stats *ll_ra_stats; - - struct ll_ra_info ll_ra_info; - unsigned int ll_namelen; - struct file_operations *ll_fop; - - struct lu_site *ll_site; - struct cl_device *ll_cl; - /* Statistics */ - struct ll_rw_extents_info ll_rw_extents_info; - int ll_extent_process_count; - struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX]; - unsigned int ll_offset_process_count; - struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX]; - unsigned int ll_rw_offset_entry_count; - int ll_stats_track_id; - enum stats_track_type ll_stats_track_type; - int ll_rw_stats_on; + struct lprocfs_stats *ll_ra_stats; + + struct ll_ra_info ll_ra_info; + unsigned int ll_namelen; + const struct file_operations *ll_fop; + + struct lu_site *ll_site; + struct cl_device *ll_cl; + /* Statistics */ + struct ll_rw_extents_info ll_rw_extents_info; + int ll_extent_process_count; + struct ll_rw_process_info ll_rw_process_info[LL_PROCESS_HIST_MAX]; + unsigned int ll_offset_process_count; + struct ll_rw_process_info ll_rw_offset_info[LL_OFFSET_HIST_MAX]; + unsigned int ll_rw_offset_entry_count; + int ll_stats_track_id; + enum stats_track_type ll_stats_track_type; + int ll_rw_stats_on; /* metadata stat-ahead */ unsigned int ll_sa_running_max;/* max concurrent @@ -1104,10 +1104,10 @@ struct ll_cl_context *ll_cl_find(struct file *file); extern const struct address_space_operations ll_aops; /* llite/file.c */ -extern struct file_operations ll_file_operations; -extern struct file_operations ll_file_operations_flock; -extern struct file_operations ll_file_operations_noflock; -extern struct inode_operations ll_file_inode_operations; +extern const struct file_operations ll_file_operations; +extern const struct file_operations ll_file_operations_flock; +extern const struct file_operations ll_file_operations_noflock; +extern const struct inode_operations ll_file_inode_operations; extern int ll_have_md_lock(struct inode *inode, __u64 *bits, enum ldlm_mode l_req_mode); extern enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits, @@ -1199,7 +1199,7 @@ int ll_revalidate_it_finish(struct ptlrpc_request *request, struct lookup_intent *it, struct dentry *de); /* llite/llite_lib.c */ -extern struct super_operations lustre_super_operations; +extern const struct super_operations lustre_super_operations; void ll_lli_init(struct ll_inode_info *lli); int ll_fill_super(struct super_block *sb); @@ -1271,14 +1271,14 @@ static inline ssize_t ll_lov_user_md_size(const struct lov_user_md *lum) } /* llite/llite_nfs.c */ -extern struct export_operations lustre_export_operations; +extern const struct export_operations lustre_export_operations; __u32 get_uuid2int(const char *name, int len); struct inode *search_inode_for_lustre(struct super_block *sb, const struct lu_fid *fid); int ll_dir_get_parent_fid(struct inode *dir, struct lu_fid *parent_fid); /* llite/symlink.c */ -extern struct inode_operations ll_fast_symlink_inode_operations; +extern const struct inode_operations ll_fast_symlink_inode_operations; /** * IO arguments for various VFS I/O interfaces. diff --git a/lustre/llite/llite_nfs.c b/lustre/llite/llite_nfs.c index 7fef62a..bf18757 100644 --- a/lustre/llite/llite_nfs.c +++ b/lustre/llite/llite_nfs.c @@ -376,7 +376,7 @@ static struct dentry *ll_get_parent(struct dentry *dchild) RETURN(dentry); } -struct export_operations lustre_export_operations = { +const struct export_operations lustre_export_operations = { .get_parent = ll_get_parent, .encode_fh = ll_encode_fh, .get_name = ll_get_name, diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index 5c5b9db..272cac9 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -81,7 +81,7 @@ static int ll_drop_inode(struct inode *inode) } /* exported operations */ -struct super_operations lustre_super_operations = +const struct super_operations lustre_super_operations = { .alloc_inode = ll_alloc_inode, .destroy_inode = ll_destroy_inode, diff --git a/lustre/llite/symlink.c b/lustre/llite/symlink.c index 85e8193..41a00cd 100644 --- a/lustre/llite/symlink.c +++ b/lustre/llite/symlink.c @@ -229,7 +229,7 @@ static const char *ll_follow_link(struct dentry *dentry, void **cookie) # endif /* HAVE_IOP_GET_LINK */ #endif /* HAVE_SYMLINK_OPS_USE_NAMEIDATA */ -struct inode_operations ll_fast_symlink_inode_operations = { +const struct inode_operations ll_fast_symlink_inode_operations = { #ifdef HAVE_IOP_GENERIC_READLINK .readlink = generic_readlink, #endif diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index cb5a8bb..b23498e 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -317,7 +317,7 @@ static int pool_proc_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations pool_proc_operations = { +const static struct file_operations pool_proc_operations = { .open = pool_proc_open, .read = seq_read, .llseek = seq_lseek, diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index f31a9a7..c5556c9 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -223,11 +223,11 @@ static int pool_proc_open(struct inode *inode, struct file *file) return rc; } -static struct file_operations pool_proc_operations = { - .open = pool_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, +const static struct file_operations pool_proc_operations = { + .open = pool_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 436f04c..a47d434 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -494,7 +494,7 @@ static long obd_class_ioctl(struct file *filp, unsigned int cmd, } /* declare character device */ -static struct file_operations obd_psdev_fops = { +static const struct file_operations obd_psdev_fops = { .owner = THIS_MODULE, .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */ }; diff --git a/lustre/obdclass/lu_ref.c b/lustre/obdclass/lu_ref.c index d88e492..a1ac74e 100644 --- a/lustre/obdclass/lu_ref.c +++ b/lustre/obdclass/lu_ref.c @@ -405,12 +405,12 @@ static int lu_ref_seq_release(struct inode *inode, struct file *file) return seq_release(inode, file); } -static struct file_operations lu_ref_dump_fops = { - .owner = THIS_MODULE, - .open = lu_ref_seq_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lu_ref_seq_release +static const struct file_operations lu_ref_dump_fops = { + .owner = THIS_MODULE, + .open = lu_ref_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = lu_ref_seq_release }; #endif /* CONFIG_PROC_FS */ diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index fa4de07..d9166d3 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -1779,7 +1779,7 @@ int server_show_options(struct seq_file *seq, struct dentry *dentry) /** The operations we support directly on the superblock: * mount, umount, and df. */ -static struct super_operations server_ops = { +static const struct super_operations server_ops = { .put_super = server_put_super, .umount_begin = server_umount_begin, /* umount -f */ .statfs = server_statfs, diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index af7b5fd..9904bcf 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -1209,14 +1209,14 @@ void ptlrpc_ldebugfs_register_service(struct dentry *entry, .fops = &ptlrpc_lprocfs_req_buffers_max_fops, .data = svc }, { NULL } - }; - static struct file_operations req_history_fops = { - .owner = THIS_MODULE, - .open = ptlrpc_lprocfs_svc_req_history_open, - .read = seq_read, - .llseek = seq_lseek, - .release = lprocfs_seq_release, - }; + }; + static const struct file_operations req_history_fops = { + .owner = THIS_MODULE, + .open = ptlrpc_lprocfs_svc_req_history_open, + .read = seq_read, + .llseek = seq_lseek, + .release = lprocfs_seq_release, + }; ptlrpc_ldebugfs_register(entry, svc->srv_name, "stats", &svc->srv_debugfs_entry, &svc->srv_stats); diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index 977079f..de78fd4 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -352,7 +352,7 @@ static int lprocfs_quota_seq_release(struct inode *inode, struct file *file) return seq_release(inode, file); } -struct file_operations lprocfs_quota_seq_fops = { +const struct file_operations lprocfs_quota_seq_fops = { .owner = THIS_MODULE, .open = lprocfs_quota_seq_open, .read = seq_read, diff --git a/lustre/quota/lquota_internal.h b/lustre/quota/lquota_internal.h index f13c1dc..2629882 100644 --- a/lustre/quota/lquota_internal.h +++ b/lustre/quota/lquota_internal.h @@ -493,7 +493,7 @@ int qmt_glb_init(void); void qmt_glb_fini(void); /* lproc_quota.c */ -extern struct file_operations lprocfs_quota_seq_fops; +extern const struct file_operations lprocfs_quota_seq_fops; /* qsd_lib.c */ int qsd_glb_init(void); -- 1.8.3.1