diff --git a/scripts/generate-kernel-patch b/scripts/generate-kernel-patch index d4a05b71b..af2f3a825 100755 --- a/scripts/generate-kernel-patch +++ b/scripts/generate-kernel-patch @@ -302,7 +302,7 @@ do done -scst_03_public_headers="scst/include/scst.h scst/include/scst_const.h" +scst_03_public_headers="scst/include/scst.h scst/include/scst_const.h scst/include/backport.h" scst_04_main="scst/src/scst_main.c scst/src/scst_module.c scst/src/scst_priv.h" scst_05_targ="scst/src/scst_targ.c" scst_06_lib="scst/src/scst_lib.c" diff --git a/scst/include/backport.h b/scst/include/backport.h new file mode 100644 index 000000000..d4c870cc5 --- /dev/null +++ b/scst/include/backport.h @@ -0,0 +1,55 @@ +#ifndef _SCST_BACKPORT_H_ +#define _SCST_BACKPORT_H_ + +/* + * Copyright (C) 2015 SanDisk Corporation + * + * Backports of functions introduced in recent kernel versions. + * + * Please keep the functions in this file sorted according to the name of the + * header file in which these have been defined. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include /* sync_page_range() */ + +/* */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) && \ + !defined(CONFIG_COMPAT_KERNEL_3_12) +/* + * See also patch "new helper: file_inode(file)" (commit ID + * 496ad9aa8ef448058e36ca7a787c61f2e63f0f54). See also patch + * "kill f_dentry macro" (commit ID 78d28e651f97). + */ +static inline struct inode *file_inode(const struct file *f) +{ + return f->f_dentry->d_inode; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +static inline int vfs_fsync_backport(struct file *file, int datasync) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) + struct inode *inode = file_inode(file); + + return sync_page_range(inode, file->f_mapping, 0, i_size_read(inode)); +#else + return vfs_fsync(file, file->f_path.dentry, datasync); +#endif +} + +#define vfs_fsync vfs_fsync_backport +#endif + +#endif /* _SCST_BACKPORT_H_ */ diff --git a/scst/include/scst.h b/scst/include/scst.h index b86f566e3..8c00799fe 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -64,8 +64,10 @@ #include #ifdef INSIDE_KERNEL_TREE +#include #include #else +#include #include #endif @@ -328,19 +330,6 @@ static inline void hex2bin(u8 *dst, const char *src, size_t count) } #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) && \ - !defined(CONFIG_COMPAT_KERNEL_3_12) -/* - * See also patch "new helper: file_inode(file)" (commit ID - * 496ad9aa8ef448058e36ca7a787c61f2e63f0f54). See also patch - * "kill f_dentry macro" (commit ID 78d28e651f97). - */ -static inline struct inode *file_inode(const struct file *f) -{ - return f->f_dentry->d_inode; -} -#endif - #ifndef __list_for_each /* ToDo: cleanup when both are the same for all relevant kernels */ #define __list_for_each list_for_each diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 251c46945..c566f9b5d 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -13147,16 +13147,6 @@ void scst_path_put(struct nameidata *nd) EXPORT_SYMBOL(scst_path_put); #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) -int scst_vfs_fsync(struct file *file, loff_t loff, loff_t len) -{ - int res; - - res = sync_page_range(file_inode(file), file->f_mapping, loff, len); - return res; -} -#endif - int scst_copy_file(const char *src, const char *dest) { int res = 0; @@ -13230,13 +13220,7 @@ int scst_copy_file(const char *src, const char *dest) goto out_skip; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - res = scst_vfs_fsync(file_dest, 0, file_size); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) - res = vfs_fsync(file_dest, file_dest->f_path.dentry, 0); -#else res = vfs_fsync(file_dest, 0); -#endif if (res != 0) { PRINT_ERROR("fsync() of the backup PR file failed: %d", res); goto out_skip; @@ -13328,13 +13312,7 @@ int scst_write_file_transactional(const char *name, const char *name1, if (res != size) goto write_error; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - res = scst_vfs_fsync(file, 0, pos); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) - res = vfs_fsync(file, file->f_path.dentry, 1); -#else res = vfs_fsync(file, 1); -#endif if (res != 0) { PRINT_ERROR("fsync() of file %s failed: %d", name, res); goto write_error_close; @@ -13349,13 +13327,7 @@ int scst_write_file_transactional(const char *name, const char *name1, if (res != sizeof(n)) goto write_error; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - res = scst_vfs_fsync(file, 0, sizeof(signature)); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) - res = vfs_fsync(file, file->f_path.dentry, 1); -#else res = vfs_fsync(file, 1); -#endif if (res != 0) { PRINT_ERROR("fsync() of file %s failed: %d", name, res); goto write_error_close; diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 56ed68cef..6e6fcad9d 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -986,13 +986,7 @@ void scst_pr_sync_device_file(struct scst_tgt_dev *tgt_dev, struct scst_cmd *cmd goto write_error; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - res = scst_vfs_fsync(file, 0, pos); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) - res = vfs_fsync(file, file->f_path.dentry, 1); -#else res = vfs_fsync(file, 1); -#endif if (res != 0) { PRINT_ERROR("fsync() of the PR file failed: %d", res); goto write_error_close; @@ -1004,13 +998,7 @@ void scst_pr_sync_device_file(struct scst_tgt_dev *tgt_dev, struct scst_cmd *cmd if (res != sizeof(sign)) goto write_error; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - res = scst_vfs_fsync(file, 0, sizeof(sign)); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) - res = vfs_fsync(file, file->f_path.dentry, 1); -#else res = vfs_fsync(file, 1); -#endif if (res != 0) { PRINT_ERROR("fsync() of the PR file failed: %d", res); goto write_error_close; diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index 78c7e84f6..198a5f4af 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -781,10 +781,6 @@ void scst_vfs_unlink_and_put(struct nameidata *nd); void scst_vfs_unlink_and_put(struct path *path); #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) -int scst_vfs_fsync(struct file *file, loff_t loff, loff_t len); -#endif - int scst_copy_file(const char *src, const char *dest); #ifdef CONFIG_SCST_DEBUG_TM