mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-17 18:51:27 +00:00
scst: Use kernel_{read,write}() instead of scst_{read,write}()
This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8065 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -452,6 +452,24 @@ kernel_read_backport(struct file *file, void *buf, size_t count, loff_t *pos)
|
||||
|
||||
#define kernel_read(file, buf, count, pos) \
|
||||
kernel_read_backport((file), (buf), (count), (pos))
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
|
||||
/*
|
||||
* See also commit 7bb307e894d5 ("export kernel_write(), convert open-coded
|
||||
* instances") # v3.9.
|
||||
*/
|
||||
static inline ssize_t
|
||||
kernel_write_backport(struct file *file, const void *buf, size_t count,
|
||||
loff_t *pos)
|
||||
{
|
||||
return kernel_write(file, buf, count, *pos);
|
||||
}
|
||||
|
||||
#define kernel_write kernel_write_backport
|
||||
#else
|
||||
ssize_t kernel_write(struct file *file, const void *buf, size_t count,
|
||||
loff_t *pos);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* <linux/iocontext.h> */
|
||||
|
||||
@@ -5599,9 +5599,6 @@ struct scst_data_descriptor {
|
||||
uint64_t sdd_blocks;
|
||||
};
|
||||
|
||||
ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos);
|
||||
ssize_t scst_write(struct file *file, const void *buf, size_t count,
|
||||
loff_t *pos);
|
||||
ssize_t scst_readv(struct file *file, const struct iovec *vec,
|
||||
unsigned long vlen, loff_t *pos);
|
||||
ssize_t scst_writev(struct file *file, const struct iovec *vec,
|
||||
|
||||
@@ -2995,21 +2995,6 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Note: Updates *@loff if reading succeeded. */
|
||||
static ssize_t fileio_read_sync(struct file *fd, void *buf, size_t len,
|
||||
loff_t *loff)
|
||||
{
|
||||
mm_segment_t old_fs;
|
||||
ssize_t ret;
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(KERNEL_DS);
|
||||
ret = scst_read(fd, buf, len, loff);
|
||||
set_fs(old_fs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Note: Updates *@loff if reading succeeded except for NULLIO devices. */
|
||||
static ssize_t vdev_read_sync(struct scst_vdisk_dev *virt_dev, void *buf,
|
||||
size_t len, loff_t *loff)
|
||||
@@ -3027,7 +3012,7 @@ static ssize_t vdev_read_sync(struct scst_vdisk_dev *virt_dev, void *buf,
|
||||
}
|
||||
return read;
|
||||
} else {
|
||||
return fileio_read_sync(virt_dev->fd, buf, len, loff);
|
||||
return kernel_read(virt_dev->fd, buf, len, loff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5933,44 +5933,31 @@ static int scst_cmp_fs_ds(void)
|
||||
return memcmp(&fs, &ds, sizeof(fs));
|
||||
}
|
||||
|
||||
ssize_t scst_read(struct file *file, void *buf, size_t count, loff_t *pos)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) && !defined(RHEL_MAJOR)
|
||||
ssize_t kernel_write(struct file *file, const void *buf, size_t count,
|
||||
loff_t *pos)
|
||||
{
|
||||
mm_segment_t old_fs = get_fs();
|
||||
ssize_t result;
|
||||
set_fs(KERNEL_DS);
|
||||
{
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
|
||||
struct iovec iov = {
|
||||
.iov_base = (void __force __user *)buf,
|
||||
.iov_len = count
|
||||
};
|
||||
|
||||
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
|
||||
|
||||
return scst_readv(file, &iov, 1, pos);
|
||||
result = scst_writev(file, &iov, 1, pos);
|
||||
#else
|
||||
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
|
||||
|
||||
return vfs_read(file, (void __force __user *)buf, count, pos);
|
||||
result = vfs_write(file, (void __force __user *)buf, count, pos);
|
||||
#endif
|
||||
}
|
||||
set_fs(old_fs);
|
||||
|
||||
return result;
|
||||
}
|
||||
EXPORT_SYMBOL(scst_read);
|
||||
|
||||
ssize_t scst_write(struct file *file, const void *buf, size_t count,
|
||||
loff_t *pos)
|
||||
{
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
|
||||
struct iovec iov = {
|
||||
.iov_base = (void __force __user *)buf,
|
||||
.iov_len = count
|
||||
};
|
||||
|
||||
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
|
||||
|
||||
return scst_writev(file, &iov, 1, pos);
|
||||
#else
|
||||
WARN_ON_ONCE(scst_cmp_fs_ds() != 0);
|
||||
|
||||
return vfs_write(file, (void __force __user *)buf, count, pos);
|
||||
EXPORT_SYMBOL(kernel_write);
|
||||
#endif
|
||||
}
|
||||
EXPORT_SYMBOL(scst_write);
|
||||
|
||||
ssize_t scst_readv(struct file *file, const struct iovec *vec,
|
||||
unsigned long vlen, loff_t *pos)
|
||||
@@ -15044,7 +15031,6 @@ int scst_copy_file(const char *src, const char *dest)
|
||||
loff_t file_size, pos;
|
||||
uint8_t *buf = NULL;
|
||||
struct file *file_src = NULL, *file_dest = NULL;
|
||||
mm_segment_t old_fs = get_fs();
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
@@ -15057,8 +15043,6 @@ int scst_copy_file(const char *src, const char *dest)
|
||||
|
||||
TRACE_DBG("Copying '%s' into '%s'", src, dest);
|
||||
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
file_src = filp_open(src, O_RDONLY, 0);
|
||||
if (IS_ERR(file_src)) {
|
||||
res = PTR_ERR(file_src);
|
||||
@@ -15083,7 +15067,6 @@ int scst_copy_file(const char *src, const char *dest)
|
||||
} else {
|
||||
PRINT_ERROR("Invalid file mode 0x%x", inode->i_mode);
|
||||
res = -EINVAL;
|
||||
set_fs(old_fs);
|
||||
goto out_skip;
|
||||
}
|
||||
|
||||
@@ -15097,14 +15080,14 @@ int scst_copy_file(const char *src, const char *dest)
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
res = scst_read(file_src, buf, file_size, &pos);
|
||||
res = kernel_read(file_src, buf, file_size, &pos);
|
||||
if (res != file_size) {
|
||||
PRINT_ERROR("Unable to read file '%s' - error %d", src, res);
|
||||
goto out_skip;
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
res = scst_write(file_dest, buf, file_size, &pos);
|
||||
res = kernel_write(file_dest, buf, file_size, &pos);
|
||||
if (res != file_size) {
|
||||
PRINT_ERROR("Unable to write to '%s' - error %d", dest, res);
|
||||
goto out_skip;
|
||||
@@ -15126,8 +15109,6 @@ out_free:
|
||||
if (buf != NULL)
|
||||
vfree(buf);
|
||||
|
||||
set_fs(old_fs);
|
||||
|
||||
out:
|
||||
TRACE_EXIT_RES(res);
|
||||
return res;
|
||||
@@ -15174,7 +15155,6 @@ int scst_write_file_transactional(const char *name, const char *name1,
|
||||
{
|
||||
int res;
|
||||
struct file *file;
|
||||
mm_segment_t old_fs = get_fs();
|
||||
loff_t pos = 0;
|
||||
char n = '\n';
|
||||
|
||||
@@ -15184,8 +15164,6 @@ int scst_write_file_transactional(const char *name, const char *name1,
|
||||
if ((res != 0) && (res != -ENOENT))
|
||||
goto out;
|
||||
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
file = filp_open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (IS_ERR(file)) {
|
||||
res = PTR_ERR(file);
|
||||
@@ -15198,7 +15176,7 @@ int scst_write_file_transactional(const char *name, const char *name1,
|
||||
|
||||
pos = signature_len+1;
|
||||
|
||||
res = scst_write(file, buf, size, &pos);
|
||||
res = kernel_write(file, buf, size, &pos);
|
||||
if (res != size)
|
||||
goto write_error;
|
||||
|
||||
@@ -15209,11 +15187,11 @@ int scst_write_file_transactional(const char *name, const char *name1,
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
res = scst_write(file, signature, signature_len, &pos);
|
||||
res = kernel_write(file, signature, signature_len, &pos);
|
||||
if (res != signature_len)
|
||||
goto write_error;
|
||||
|
||||
res = scst_write(file, &n, sizeof(n), &pos);
|
||||
res = kernel_write(file, &n, sizeof(n), &pos);
|
||||
if (res != sizeof(n))
|
||||
goto write_error;
|
||||
|
||||
@@ -15228,8 +15206,6 @@ int scst_write_file_transactional(const char *name, const char *name1,
|
||||
filp_close(file, NULL);
|
||||
|
||||
out_set_fs:
|
||||
set_fs(old_fs);
|
||||
|
||||
if (res == 0)
|
||||
scst_remove_file(name1);
|
||||
else
|
||||
@@ -15257,13 +15233,9 @@ static int __scst_read_file_transactional(const char *file_name,
|
||||
struct file *file = NULL;
|
||||
struct inode *inode;
|
||||
loff_t file_size, pos;
|
||||
mm_segment_t old_fs;
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
TRACE_DBG("Loading file '%s'", file_name);
|
||||
|
||||
file = filp_open(file_name, O_RDONLY, 0);
|
||||
@@ -15295,7 +15267,7 @@ static int __scst_read_file_transactional(const char *file_name,
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
res = scst_read(file, buf, file_size, &pos);
|
||||
res = kernel_read(file, buf, file_size, &pos);
|
||||
if (res != file_size) {
|
||||
PRINT_ERROR("Unable to read file '%s' - error %d", file_name, res);
|
||||
if (res > 0)
|
||||
@@ -15313,8 +15285,6 @@ out_close:
|
||||
filp_close(file, NULL);
|
||||
|
||||
out:
|
||||
set_fs(old_fs);
|
||||
|
||||
TRACE_EXIT_RES(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -664,7 +664,6 @@ static int scst_pr_do_load_device_file(struct scst_device *dev,
|
||||
char *buf = NULL;
|
||||
loff_t file_size, pos, data_size;
|
||||
uint64_t sign, version;
|
||||
mm_segment_t old_fs;
|
||||
uint8_t pr_is_set, aptpl;
|
||||
__be64 key;
|
||||
uint16_t rel_tgt_id;
|
||||
@@ -675,9 +674,6 @@ static int scst_pr_do_load_device_file(struct scst_device *dev,
|
||||
|
||||
scst_pr_remove_registrants(dev);
|
||||
|
||||
old_fs = get_fs();
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
TRACE_PR("Loading persistent file '%s'", file_name);
|
||||
|
||||
file = filp_open(file_name, O_RDONLY, 0);
|
||||
@@ -715,7 +711,7 @@ static int scst_pr_do_load_device_file(struct scst_device *dev,
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
rc = scst_read(file, buf, file_size, &pos);
|
||||
rc = kernel_read(file, buf, file_size, &pos);
|
||||
if (rc != file_size) {
|
||||
PRINT_ERROR("Unable to read file '%s' - error %d", file_name,
|
||||
rc);
|
||||
@@ -822,8 +818,6 @@ out:
|
||||
if (buf != NULL)
|
||||
vfree(buf);
|
||||
|
||||
set_fs(old_fs);
|
||||
|
||||
TRACE_EXIT_RES(res);
|
||||
return res;
|
||||
}
|
||||
@@ -885,7 +879,6 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
{
|
||||
int res = 0;
|
||||
struct file *file;
|
||||
mm_segment_t old_fs = get_fs();
|
||||
loff_t pos = 0;
|
||||
uint64_t sign;
|
||||
uint64_t version;
|
||||
@@ -903,14 +896,12 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
|
||||
scst_copy_file(dev->pr_file_name, dev->pr_file_name1);
|
||||
|
||||
set_fs(KERNEL_DS);
|
||||
|
||||
file = filp_open(dev->pr_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (IS_ERR(file)) {
|
||||
res = PTR_ERR(file);
|
||||
PRINT_ERROR("Unable to (re)create PR file '%s' - error %d",
|
||||
dev->pr_file_name, res);
|
||||
goto out_set_fs;
|
||||
goto out;
|
||||
}
|
||||
|
||||
TRACE_PR("Updating pr file '%s'", dev->pr_file_name);
|
||||
@@ -920,7 +911,7 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
*/
|
||||
sign = 0;
|
||||
pos = 0;
|
||||
res = scst_write(file, &sign, sizeof(sign), &pos);
|
||||
res = kernel_write(file, &sign, sizeof(sign), &pos);
|
||||
if (res != sizeof(sign))
|
||||
goto write_error;
|
||||
|
||||
@@ -928,7 +919,7 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
* version
|
||||
*/
|
||||
version = SCST_PR_FILE_VERSION;
|
||||
res = scst_write(file, &version, sizeof(version), &pos);
|
||||
res = kernel_write(file, &version, sizeof(version), &pos);
|
||||
if (res != sizeof(version))
|
||||
goto write_error;
|
||||
|
||||
@@ -936,7 +927,7 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
* APTPL
|
||||
*/
|
||||
aptpl = dev->pr_aptpl;
|
||||
res = scst_write(file, &aptpl, sizeof(aptpl), &pos);
|
||||
res = kernel_write(file, &aptpl, sizeof(aptpl), &pos);
|
||||
if (res != sizeof(aptpl))
|
||||
goto write_error;
|
||||
|
||||
@@ -944,15 +935,15 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
* reservation
|
||||
*/
|
||||
pr_is_set = dev->pr_is_set;
|
||||
res = scst_write(file, &pr_is_set, sizeof(pr_is_set), &pos);
|
||||
res = kernel_write(file, &pr_is_set, sizeof(pr_is_set), &pos);
|
||||
if (res != sizeof(pr_is_set))
|
||||
goto write_error;
|
||||
|
||||
res = scst_write(file, &dev->pr_type, sizeof(dev->pr_type), &pos);
|
||||
res = kernel_write(file, &dev->pr_type, sizeof(dev->pr_type), &pos);
|
||||
if (res != sizeof(dev->pr_type))
|
||||
goto write_error;
|
||||
|
||||
res = scst_write(file, &dev->pr_scope, sizeof(dev->pr_scope), &pos);
|
||||
res = kernel_write(file, &dev->pr_scope, sizeof(dev->pr_scope), &pos);
|
||||
if (res != sizeof(dev->pr_scope))
|
||||
goto write_error;
|
||||
|
||||
@@ -966,24 +957,21 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
|
||||
is_holder = (dev->pr_holder == reg);
|
||||
|
||||
res = scst_write(file, &is_holder,
|
||||
sizeof(is_holder), &pos);
|
||||
res = kernel_write(file, &is_holder, sizeof(is_holder), &pos);
|
||||
if (res != sizeof(is_holder))
|
||||
goto write_error;
|
||||
|
||||
size = scst_tid_size(reg->transport_id);
|
||||
res = scst_write(file, reg->transport_id,
|
||||
size, &pos);
|
||||
res = kernel_write(file, reg->transport_id, size, &pos);
|
||||
if (res != size)
|
||||
goto write_error;
|
||||
|
||||
res = scst_write(file, ®->key,
|
||||
sizeof(reg->key), &pos);
|
||||
res = kernel_write(file, ®->key, sizeof(reg->key), &pos);
|
||||
if (res != sizeof(reg->key))
|
||||
goto write_error;
|
||||
|
||||
res = scst_write(file, ®->rel_tgt_id,
|
||||
sizeof(reg->rel_tgt_id), &pos);
|
||||
res = kernel_write(file, ®->rel_tgt_id,
|
||||
sizeof(reg->rel_tgt_id), &pos);
|
||||
if (res != sizeof(reg->rel_tgt_id))
|
||||
goto write_error;
|
||||
}
|
||||
@@ -996,7 +984,7 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
|
||||
sign = SCST_PR_FILE_SIGN;
|
||||
pos = 0;
|
||||
res = scst_write(file, &sign, sizeof(sign), &pos);
|
||||
res = kernel_write(file, &sign, sizeof(sign), &pos);
|
||||
if (res != sizeof(sign))
|
||||
goto write_error;
|
||||
|
||||
@@ -1010,9 +998,6 @@ void scst_pr_sync_device_file(struct scst_device *dev)
|
||||
|
||||
filp_close(file, NULL);
|
||||
|
||||
out_set_fs:
|
||||
set_fs(old_fs);
|
||||
|
||||
out:
|
||||
if (res != 0) {
|
||||
PRINT_CRIT_ERROR("Unable to save persistent information "
|
||||
@@ -1057,7 +1042,7 @@ write_error_close:
|
||||
dev->pr_file_name, rc);
|
||||
}
|
||||
#endif
|
||||
goto out_set_fs;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user