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 206eeeb7c..9a9232b09 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -65,8 +65,10 @@ #include #ifdef INSIDE_KERNEL_TREE +#include #include #else +#include #include #endif @@ -329,19 +331,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 c563e43d0..e65a1b388 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -13320,16 +13320,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; @@ -13403,13 +13393,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; @@ -13501,13 +13485,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; @@ -13522,13 +13500,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 e24f20b8e..acc04481d 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -990,13 +990,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; @@ -1008,13 +1002,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 253709577..f40861829 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -824,10 +824,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 diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm index a74d5ad03..9b9e5db2f 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm @@ -542,28 +542,26 @@ sub setScstAttribute { SCST_C_ATTRIBUTE_STATIC); } -my @_drivers; sub drivers { my $self = shift; + my $dHandle = new IO::Handle; + my $_path = SCST_TARGETS_DIR(); + my @drivers; - if (!@_drivers) { - my $dHandle = new IO::Handle; - my $_path = SCST_TARGETS_DIR(); - if (opendir $dHandle, $_path) { - foreach my $driver (readdir($dHandle)) { - next if (($driver eq '.') || ($driver eq '..')); + if (opendir($dHandle, $_path)) { + foreach my $driver (readdir($dHandle)) { + next if (($driver eq '.') || ($driver eq '..')); - if (-d make_path(SCST_TARGETS_DIR(), $driver)) { - push @_drivers, $driver; - } + if (-d make_path(SCST_TARGETS_DIR(), $driver)) { + push @drivers, $driver; } - close $dHandle; - } else { - return (undef, "drivers(): Unable to read directory '$_path': $!"); } + close $dHandle; + } else { + return (undef, "drivers(): Unable to read directory '$_path': $!"); } - return (\@_drivers, undef); + return (\@drivers, undef); } @@ -924,18 +922,14 @@ sub targetGroupTargets { sub driverExists { my $self = shift; my $driver = shift; + my $dHandle = new IO::Handle; + my $result; - return FALSE if (!defined($driver)); + $result = defined($driver) && + opendir($dHandle, make_path(SCST_TARGETS_DIR(), $driver)); + close $dHandle if ($result); - my ($drivers, $errorString) = $self->drivers(); - - return SCST_C_FATAL_ERROR if (!defined($drivers)); - - foreach my $_driver (@{$drivers}) { - return TRUE if ($driver eq $_driver); - } - - return FALSE; + return $result; } sub driverDynamicAttributes { diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index a0f7ebb44..60d609717 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -72,12 +72,14 @@ Set Attribute Operations -attributes -set_drv_attr : Sets driver attribute(s)

to value . -attributes - -set_dgrp_attr : List all attributes for a given device group. + -set_dgrp_attr : Sets device group attribute(s)

to value . -attributes - -set_tgrp_attr : List all attributes for a device group/target. + -set_tgrp_attr : Sets device group/target attribute(s) +

to value . -dev_group -attributes - -set_ttgt_attr : List all attributes for a target group target. + -set_ttgt_attr : Set target group target attribute(s) +

to value . -dev_group -tgt_group -attributes