License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
// SPDX-License-Identifier: GPL-2.0
2015-07-17 17:38:12 +03:00
/*
* ( C ) 2001 Clemson University and The University of Chicago
*
* Changes by Acxiom Corporation to add protocol version to kernel
* communication , Copyright Acxiom Corporation , 2005.
*
* See COPYING in top - level directory .
*/
# include "protocol.h"
2015-12-04 20:56:14 +03:00
# include "orangefs-kernel.h"
# include "orangefs-dev-proto.h"
# include "orangefs-bufmap.h"
2016-08-15 18:38:36 +03:00
# include "orangefs-debugfs.h"
2015-07-17 17:38:12 +03:00
# include <linux/debugfs.h>
# include <linux/slab.h>
/* this file implements the /dev/pvfs2-req device node */
2016-08-12 19:02:31 +03:00
uint32_t orangefs_userspace_version ;
2016-08-09 22:59:26 +03:00
2015-07-17 17:38:12 +03:00
static int open_access_count ;
2016-08-15 22:21:16 +03:00
static DEFINE_MUTEX ( devreq_mutex ) ;
2015-07-17 17:38:12 +03:00
# define DUMP_DEVICE_ERROR() \
do { \
gossip_err ( " ***************************************************** \n " ) ; \
2015-11-24 23:12:14 +03:00
gossip_err ( " ORANGEFS Device Error: You cannot open the device file " ) ; \
2015-07-17 17:38:12 +03:00
gossip_err ( " \n /dev/%s more than once. Please make sure that \n there " \
2015-11-24 23:12:14 +03:00
" are no " , ORANGEFS_REQDEVICE_NAME ) ; \
2015-07-17 17:38:12 +03:00
gossip_err ( " instances of a program using this device \n currently " \
" running. (You must verify this!) \n " ) ; \
gossip_err ( " For example, you can use the lsof program as follows: \n " ) ; \
gossip_err ( " 'lsof | grep %s' (run this as root) \n " , \
2015-11-24 23:12:14 +03:00
ORANGEFS_REQDEVICE_NAME ) ; \
2015-07-17 17:38:12 +03:00
gossip_err ( " open_access_count = %d \n " , open_access_count ) ; \
gossip_err ( " ***************************************************** \n " ) ; \
} while ( 0 )
static int hash_func ( __u64 tag , int table_size )
{
2015-07-24 17:37:15 +03:00
return do_div ( tag , ( unsigned int ) table_size ) ;
2015-07-17 17:38:12 +03:00
}
2015-11-24 23:12:14 +03:00
static void orangefs_devreq_add_op ( struct orangefs_kernel_op_s * op )
2015-07-17 17:38:12 +03:00
{
int index = hash_func ( op - > tag , hash_table_size ) ;
2016-08-16 18:38:14 +03:00
list_add_tail ( & op - > list , & orangefs_htable_ops_in_progress [ index ] ) ;
2015-07-17 17:38:12 +03:00
}
2016-02-26 18:21:12 +03:00
/*
* find the op with this tag and remove it from the in progress
* hash table .
*/
2015-11-24 23:12:14 +03:00
static struct orangefs_kernel_op_s * orangefs_devreq_remove_op ( __u64 tag )
2015-07-17 17:38:12 +03:00
{
2015-11-24 23:12:14 +03:00
struct orangefs_kernel_op_s * op , * next ;
2015-07-17 17:38:12 +03:00
int index ;
index = hash_func ( tag , hash_table_size ) ;
2016-08-16 18:38:14 +03:00
spin_lock ( & orangefs_htable_ops_in_progress_lock ) ;
2015-07-17 17:38:12 +03:00
list_for_each_entry_safe ( op ,
next ,
2016-08-16 18:38:14 +03:00
& orangefs_htable_ops_in_progress [ index ] ,
2015-07-17 17:38:12 +03:00
list ) {
2016-02-19 02:59:44 +03:00
if ( op - > tag = = tag & & ! op_state_purged ( op ) & &
! op_state_given_up ( op ) ) {
2016-01-23 03:47:47 +03:00
list_del_init ( & op - > list ) ;
2016-08-16 18:38:14 +03:00
spin_unlock ( & orangefs_htable_ops_in_progress_lock ) ;
2015-07-17 17:38:12 +03:00
return op ;
}
}
2016-08-16 18:38:14 +03:00
spin_unlock ( & orangefs_htable_ops_in_progress_lock ) ;
2015-07-17 17:38:12 +03:00
return NULL ;
}
2016-03-05 21:17:39 +03:00
/* Returns whether any FS are still pending remounted */
static int mark_all_pending_mounts ( void )
{
int unmounted = 1 ;
struct orangefs_sb_info_s * orangefs_sb = NULL ;
spin_lock ( & orangefs_superblocks_lock ) ;
list_for_each_entry ( orangefs_sb , & orangefs_superblocks , list ) {
/* All of these file system require a remount */
orangefs_sb - > mount_pending = 1 ;
unmounted = 0 ;
}
spin_unlock ( & orangefs_superblocks_lock ) ;
return unmounted ;
}
/*
* Determine if a given file system needs to be remounted or not
* Returns - 1 on error
* 0 if already mounted
* 1 if needs remount
*/
static int fs_mount_pending ( __s32 fsid )
{
int mount_pending = - 1 ;
struct orangefs_sb_info_s * orangefs_sb = NULL ;
spin_lock ( & orangefs_superblocks_lock ) ;
list_for_each_entry ( orangefs_sb , & orangefs_superblocks , list ) {
if ( orangefs_sb - > fs_id = = fsid ) {
mount_pending = orangefs_sb - > mount_pending ;
break ;
}
}
spin_unlock ( & orangefs_superblocks_lock ) ;
return mount_pending ;
}
2015-11-24 23:12:14 +03:00
static int orangefs_devreq_open ( struct inode * inode , struct file * file )
2015-07-17 17:38:12 +03:00
{
int ret = - EINVAL ;
orangefs: fix namespace handling
In orangefs_inode_getxattr(), an fsuid is written to dmesg. The kuid is
converted to a userspace uid via from_kuid(current_user_ns(), [...]), but
since dmesg is global, init_user_ns should be used here instead.
In copy_attributes_from_inode(), op_alloc() and fill_default_sys_attrs(),
upcall structures are populated with uids/gids that have been mapped into
the caller's namespace. However, those upcall structures are read by
another process (the userspace filesystem driver), and that process might
be running in another namespace. This effectively lets any user spoof its
uid and gid as seen by the userspace filesystem driver.
To fix the second issue, I just construct the opcall structures with
init_user_ns uids/gids and require the filesystem server to run in the
init namespace. Since orangefs is full of global state anyway (as the error
message in DUMP_DEVICE_ERROR explains, there can only be one userspace
orangefs filesystem driver at once), that shouldn't be a problem.
[
Why does orangefs even exist in the kernel if everything does upcalls into
userspace? What does orangefs do that couldn't be done with the FUSE
interface? If there is no good answer to those questions, I'd prefer to see
orangefs kicked out of the kernel. Can that be done for something that
shipped in a release?
According to commit f7ab093f74bf ("Orangefs: kernel client part 1"), they
even already have a FUSE daemon, and the only rational reason (apart from
"but most of our users report preferring to use our kernel module instead")
given for not wanting to use FUSE is one "in-the-works" feature that could
probably be integated into FUSE instead.
]
This patch has been compile-tested.
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2016-06-25 02:51:52 +03:00
/* in order to ensure that the filesystem driver sees correct UIDs */
if ( file - > f_cred - > user_ns ! = & init_user_ns ) {
gossip_err ( " %s: device cannot be opened outside init_user_ns \n " ,
__func__ ) ;
goto out ;
}
2015-07-17 17:38:12 +03:00
if ( ! ( file - > f_flags & O_NONBLOCK ) ) {
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
gossip_err ( " %s: device cannot be opened in blocking mode \n " ,
__func__ ) ;
2015-07-17 17:38:12 +03:00
goto out ;
}
ret = - EACCES ;
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG , " client-core: opening device \n " ) ;
2015-07-17 17:38:12 +03:00
mutex_lock ( & devreq_mutex ) ;
if ( open_access_count = = 0 ) {
2016-01-23 03:46:08 +03:00
open_access_count = 1 ;
2016-01-19 20:00:26 +03:00
ret = 0 ;
2015-07-17 17:38:12 +03:00
} else {
DUMP_DEVICE_ERROR ( ) ;
}
mutex_unlock ( & devreq_mutex ) ;
out :
gossip_debug ( GOSSIP_DEV_DEBUG ,
" pvfs2-client-core: open device complete (ret = %d) \n " ,
ret ) ;
return ret ;
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
/* Function for read() callers into the device */
2015-11-24 23:12:14 +03:00
static ssize_t orangefs_devreq_read ( struct file * file ,
2015-07-17 17:38:12 +03:00
char __user * buf ,
size_t count , loff_t * offset )
{
2015-11-24 23:12:14 +03:00
struct orangefs_kernel_op_s * op , * temp ;
__s32 proto_ver = ORANGEFS_KERNEL_PROTO_VERSION ;
static __s32 magic = ORANGEFS_DEVREQ_MAGIC ;
2018-01-22 23:44:52 +03:00
struct orangefs_kernel_op_s * cur_op ;
2015-11-13 22:26:10 +03:00
unsigned long ret ;
2015-07-17 17:38:12 +03:00
2015-11-13 22:26:10 +03:00
/* We do not support blocking IO. */
2015-07-17 17:38:12 +03:00
if ( ! ( file - > f_flags & O_NONBLOCK ) ) {
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
gossip_err ( " %s: blocking read from client-core. \n " ,
__func__ ) ;
2015-07-17 17:38:12 +03:00
return - EINVAL ;
2015-11-13 22:26:10 +03:00
}
/*
2015-12-15 22:22:06 +03:00
* The client will do an ioctl to find MAX_DEV_REQ_UPSIZE , then
2015-11-13 22:26:10 +03:00
* always read with that size buffer .
*/
2015-12-15 22:22:06 +03:00
if ( count ! = MAX_DEV_REQ_UPSIZE ) {
2015-11-13 22:26:10 +03:00
gossip_err ( " orangefs: client-core tried to read wrong size \n " ) ;
return - EINVAL ;
}
2017-04-25 22:38:06 +03:00
/* Check for an empty list before locking. */
if ( list_empty ( & orangefs_request_list ) )
return - EAGAIN ;
2016-01-23 03:47:47 +03:00
restart :
2018-01-22 23:44:52 +03:00
cur_op = NULL ;
2015-11-13 22:26:10 +03:00
/* Get next op (if any) from top of list. */
2015-11-24 23:12:14 +03:00
spin_lock ( & orangefs_request_list_lock ) ;
list_for_each_entry_safe ( op , temp , & orangefs_request_list , list ) {
2015-11-13 22:26:10 +03:00
__s32 fsid ;
/* This lock is held past the end of the loop when we break. */
spin_lock ( & op - > lock ) ;
2016-02-19 02:59:44 +03:00
if ( unlikely ( op_state_purged ( op ) | | op_state_given_up ( op ) ) ) {
2016-01-23 03:47:47 +03:00
spin_unlock ( & op - > lock ) ;
continue ;
}
2015-11-13 22:26:10 +03:00
fsid = fsid_of_op ( op ) ;
2015-11-24 23:12:14 +03:00
if ( fsid ! = ORANGEFS_FS_ID_NULL ) {
2015-11-13 22:26:10 +03:00
int ret ;
/* Skip ops whose filesystem needs to be mounted. */
ret = fs_mount_pending ( fsid ) ;
if ( ret = = 1 ) {
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
2016-02-04 21:29:27 +03:00
" %s: mount pending, skipping op tag "
" %llu %s \n " ,
__func__ ,
llu ( op - > tag ) ,
get_opname_string ( op ) ) ;
2015-11-13 22:26:10 +03:00
spin_unlock ( & op - > lock ) ;
continue ;
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
/*
* Skip ops whose filesystem we don ' t know about unless
2017-04-14 21:22:41 +03:00
* it is being mounted or unmounted . It is possible for
* a filesystem we don ' t know about to be unmounted if
* it fails to mount in the kernel after userspace has
* been sent the mount request .
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
*/
2015-11-13 22:26:10 +03:00
/* XXX: is there a better way to detect this? */
} else if ( ret = = - 1 & &
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
! ( op - > upcall . type = =
ORANGEFS_VFS_OP_FS_MOUNT | |
op - > upcall . type = =
2017-04-14 21:22:41 +03:00
ORANGEFS_VFS_OP_GETATTR | |
op - > upcall . type = =
ORANGEFS_VFS_OP_FS_UMOUNT ) ) {
2015-11-13 22:26:10 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" orangefs: skipping op tag %llu %s \n " ,
llu ( op - > tag ) , get_opname_string ( op ) ) ;
gossip_err (
" orangefs: ERROR: fs_mount_pending %d \n " ,
fsid ) ;
spin_unlock ( & op - > lock ) ;
2015-07-17 17:38:12 +03:00
continue ;
}
}
2015-11-13 22:26:10 +03:00
/*
* Either this op does not pertain to a filesystem , is mounting
* a filesystem , or pertains to a mounted filesystem . Let it
* through .
*/
cur_op = op ;
break ;
}
/*
* At this point we either have a valid op and can continue or have not
* found an op and must ask the client to try again later .
*/
if ( ! cur_op ) {
2015-11-24 23:12:14 +03:00
spin_unlock ( & orangefs_request_list_lock ) ;
2015-11-13 22:26:10 +03:00
return - EAGAIN ;
2015-07-17 17:38:12 +03:00
}
2016-02-26 18:21:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG , " %s: reading op tag %llu %s \n " ,
__func__ ,
llu ( cur_op - > tag ) ,
get_opname_string ( cur_op ) ) ;
2015-07-17 17:38:12 +03:00
2015-11-13 22:26:10 +03:00
/*
* Such an op should never be on the list in the first place . If so , we
* will abort .
*/
if ( op_state_in_progress ( cur_op ) | | op_state_serviced ( cur_op ) ) {
gossip_err ( " orangefs: ERROR: Current op already queued. \n " ) ;
2016-02-19 02:59:44 +03:00
list_del_init ( & cur_op - > list ) ;
2015-07-17 17:38:12 +03:00
spin_unlock ( & cur_op - > lock ) ;
2015-11-24 23:12:14 +03:00
spin_unlock ( & orangefs_request_list_lock ) ;
2015-11-13 22:26:10 +03:00
return - EAGAIN ;
2015-07-17 17:38:12 +03:00
}
2016-02-26 18:21:12 +03:00
2016-01-23 03:47:47 +03:00
list_del_init ( & cur_op - > list ) ;
2015-11-24 23:12:14 +03:00
spin_unlock ( & orangefs_request_list_lock ) ;
2016-01-23 03:47:47 +03:00
2015-11-13 22:26:10 +03:00
spin_unlock ( & cur_op - > lock ) ;
/* Push the upcall out. */
ret = copy_to_user ( buf , & proto_ver , sizeof ( __s32 ) ) ;
if ( ret ! = 0 )
goto error ;
2018-05-12 00:11:48 +03:00
ret = copy_to_user ( buf + sizeof ( __s32 ) , & magic , sizeof ( __s32 ) ) ;
2015-11-13 22:26:10 +03:00
if ( ret ! = 0 )
goto error ;
2018-05-12 00:11:48 +03:00
ret = copy_to_user ( buf + 2 * sizeof ( __s32 ) ,
& cur_op - > tag ,
sizeof ( __u64 ) ) ;
2015-11-13 22:26:10 +03:00
if ( ret ! = 0 )
goto error ;
2018-05-12 00:11:48 +03:00
ret = copy_to_user ( buf + 2 * sizeof ( __s32 ) + sizeof ( __u64 ) ,
& cur_op - > upcall ,
sizeof ( struct orangefs_upcall_s ) ) ;
2015-11-13 22:26:10 +03:00
if ( ret ! = 0 )
goto error ;
2016-08-16 18:38:14 +03:00
spin_lock ( & orangefs_htable_ops_in_progress_lock ) ;
2016-01-23 03:47:47 +03:00
spin_lock ( & cur_op - > lock ) ;
if ( unlikely ( op_state_given_up ( cur_op ) ) ) {
spin_unlock ( & cur_op - > lock ) ;
2016-08-16 18:38:14 +03:00
spin_unlock ( & orangefs_htable_ops_in_progress_lock ) ;
2016-02-19 02:59:44 +03:00
complete ( & cur_op - > waitq ) ;
2016-01-23 03:47:47 +03:00
goto restart ;
}
/*
* Set the operation to be in progress and move it between lists since
* it has been sent to the client .
*/
set_op_state_inprogress ( cur_op ) ;
2016-03-03 21:46:48 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s: 1 op:%s: op_state:%d: process:%s: \n " ,
__func__ ,
get_opname_string ( cur_op ) ,
cur_op - > op_state ,
current - > comm ) ;
2016-01-23 03:47:47 +03:00
orangefs_devreq_add_op ( cur_op ) ;
spin_unlock ( & cur_op - > lock ) ;
2016-08-16 18:38:14 +03:00
spin_unlock ( & orangefs_htable_ops_in_progress_lock ) ;
2016-01-23 03:47:47 +03:00
2015-11-13 22:26:10 +03:00
/* The client only asks to read one size buffer. */
2015-12-15 22:22:06 +03:00
return MAX_DEV_REQ_UPSIZE ;
2015-11-13 22:26:10 +03:00
error :
/*
* We were unable to copy the op data to the client . Put the op back in
* list . If client has crashed , the op will be purged later when the
* device is released .
*/
gossip_err ( " orangefs: Failed to copy data to user space \n " ) ;
2015-11-24 23:12:14 +03:00
spin_lock ( & orangefs_request_list_lock ) ;
2015-11-13 22:26:10 +03:00
spin_lock ( & cur_op - > lock ) ;
2016-01-23 03:47:47 +03:00
if ( likely ( ! op_state_given_up ( cur_op ) ) ) {
set_op_state_waiting ( cur_op ) ;
2016-03-03 21:46:48 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s: 2 op:%s: op_state:%d: process:%s: \n " ,
__func__ ,
get_opname_string ( cur_op ) ,
cur_op - > op_state ,
current - > comm ) ;
2016-01-23 03:47:47 +03:00
list_add ( & cur_op - > list , & orangefs_request_list ) ;
2016-02-19 02:59:44 +03:00
spin_unlock ( & cur_op - > lock ) ;
} else {
spin_unlock ( & cur_op - > lock ) ;
complete ( & cur_op - > waitq ) ;
2016-01-23 03:47:47 +03:00
}
2015-11-24 23:12:14 +03:00
spin_unlock ( & orangefs_request_list_lock ) ;
2015-11-13 22:26:10 +03:00
return - EFAULT ;
2015-07-17 17:38:12 +03:00
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
/*
2016-01-13 19:18:12 +03:00
* Function for writev ( ) callers into the device .
*
* Userspace should have written :
* - __u32 version
* - __u32 magic
* - __u64 tag
* - struct orangefs_downcall_s
* - trailer buffer ( in the case of READDIR operations )
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
*/
2016-01-13 19:18:12 +03:00
static ssize_t orangefs_devreq_write_iter ( struct kiocb * iocb ,
struct iov_iter * iter )
2015-07-17 17:38:12 +03:00
{
2016-01-13 19:18:12 +03:00
ssize_t ret ;
2015-11-24 23:12:14 +03:00
struct orangefs_kernel_op_s * op = NULL ;
2016-01-13 19:18:12 +03:00
struct {
__u32 version ;
__u32 magic ;
__u64 tag ;
} head ;
int total = ret = iov_iter_count ( iter ) ;
int downcall_size = sizeof ( struct orangefs_downcall_s ) ;
int head_size = sizeof ( head ) ;
gossip_debug ( GOSSIP_DEV_DEBUG , " %s: total:%d: ret:%zd: \n " ,
__func__ ,
total ,
ret ) ;
2015-07-17 17:38:12 +03:00
2016-01-13 19:18:12 +03:00
if ( total < MAX_DEV_REQ_DOWNSIZE ) {
2016-01-19 20:04:40 +03:00
gossip_err ( " %s: total:%d: must be at least:%u: \n " ,
2016-01-13 19:18:12 +03:00
__func__ ,
total ,
2016-01-19 20:04:40 +03:00
( unsigned int ) MAX_DEV_REQ_DOWNSIZE ) ;
2016-01-23 03:47:47 +03:00
return - EFAULT ;
2015-07-17 17:38:12 +03:00
}
2018-05-12 00:11:48 +03:00
2016-11-02 05:09:04 +03:00
if ( ! copy_from_iter_full ( & head , head_size , iter ) ) {
2016-01-13 19:18:12 +03:00
gossip_err ( " %s: failed to copy head. \n " , __func__ ) ;
2016-01-23 03:47:47 +03:00
return - EFAULT ;
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
}
2016-01-13 19:18:12 +03:00
if ( head . version < ORANGEFS_MINIMUM_USERSPACE_VERSION ) {
gossip_err ( " %s: userspace claims version "
" %d, minimum version required: %d. \n " ,
__func__ ,
head . version ,
ORANGEFS_MINIMUM_USERSPACE_VERSION ) ;
2016-01-23 03:47:47 +03:00
return - EPROTO ;
2015-07-17 17:38:12 +03:00
}
2016-01-13 19:18:12 +03:00
if ( head . magic ! = ORANGEFS_DEVREQ_MAGIC ) {
gossip_err ( " Error: Device magic number does not match. \n " ) ;
2016-01-23 03:47:47 +03:00
return - EPROTO ;
2016-01-13 19:18:12 +03:00
}
2015-07-17 17:38:12 +03:00
2016-08-12 19:02:31 +03:00
if ( ! orangefs_userspace_version ) {
orangefs_userspace_version = head . version ;
} else if ( orangefs_userspace_version ! = head . version ) {
2016-08-09 22:59:26 +03:00
gossip_err ( " Error: userspace version changes \n " ) ;
return - EPROTO ;
}
2016-02-26 18:21:12 +03:00
/* remove the op from the in progress hash table */
2016-01-13 19:18:12 +03:00
op = orangefs_devreq_remove_op ( head . tag ) ;
if ( ! op ) {
2017-02-09 22:38:50 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s: No one's waiting for tag %llu \n " ,
__func__ , llu ( head . tag ) ) ;
2016-01-23 03:47:47 +03:00
return ret ;
2016-01-13 19:18:12 +03:00
}
2015-07-17 17:38:12 +03:00
2016-11-02 05:09:04 +03:00
if ( ! copy_from_iter_full ( & op - > downcall , downcall_size , iter ) ) {
2016-01-13 19:18:12 +03:00
gossip_err ( " %s: failed to copy downcall. \n " , __func__ ) ;
2016-02-19 02:53:41 +03:00
goto Efault ;
2015-07-17 17:38:12 +03:00
}
2016-01-13 19:18:12 +03:00
if ( op - > downcall . status )
goto wakeup ;
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
2016-01-13 19:18:12 +03:00
/*
2018-05-12 00:11:48 +03:00
* We ' ve successfully peeled off the head and the downcall .
2016-01-13 19:18:12 +03:00
* Something has gone awry if total doesn ' t equal the
* sum of head_size , downcall_size and trailer_size .
*/
if ( ( head_size + downcall_size + op - > downcall . trailer_size ) ! = total ) {
gossip_err ( " %s: funky write, head_size:%d "
" : downcall_size:%d: trailer_size:%lld "
" : total size:%d: \n " ,
__func__ ,
head_size ,
downcall_size ,
op - > downcall . trailer_size ,
total ) ;
2016-02-19 02:53:41 +03:00
goto Efault ;
2016-01-13 19:18:12 +03:00
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
2016-01-13 19:18:12 +03:00
/* Only READDIR operations should have trailers. */
if ( ( op - > downcall . type ! = ORANGEFS_VFS_OP_READDIR ) & &
( op - > downcall . trailer_size ! = 0 ) ) {
gossip_err ( " %s: %x operation with trailer. " ,
__func__ ,
op - > downcall . type ) ;
2016-02-19 02:53:41 +03:00
goto Efault ;
2016-01-13 19:18:12 +03:00
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
2016-01-13 19:18:12 +03:00
/* READDIR operations should always have trailers. */
if ( ( op - > downcall . type = = ORANGEFS_VFS_OP_READDIR ) & &
( op - > downcall . trailer_size = = 0 ) ) {
gossip_err ( " %s: %x operation with no trailer. " ,
__func__ ,
op - > downcall . type ) ;
2016-02-19 02:53:41 +03:00
goto Efault ;
2016-01-13 19:18:12 +03:00
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
2016-01-13 19:18:12 +03:00
if ( op - > downcall . type ! = ORANGEFS_VFS_OP_READDIR )
goto wakeup ;
2015-07-17 17:38:12 +03:00
2018-01-26 22:42:47 +03:00
op - > downcall . trailer_buf = vzalloc ( op - > downcall . trailer_size ) ;
2017-08-17 22:00:07 +03:00
if ( ! op - > downcall . trailer_buf )
2016-02-19 02:53:41 +03:00
goto Enomem ;
2017-08-17 22:00:07 +03:00
2016-11-02 05:09:04 +03:00
if ( ! copy_from_iter_full ( op - > downcall . trailer_buf ,
op - > downcall . trailer_size , iter ) ) {
2016-01-13 19:18:12 +03:00
gossip_err ( " %s: failed to copy trailer. \n " , __func__ ) ;
vfree ( op - > downcall . trailer_buf ) ;
2016-02-19 02:53:41 +03:00
goto Efault ;
2016-01-13 19:18:12 +03:00
}
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
2016-01-13 19:18:12 +03:00
wakeup :
2016-01-23 21:45:46 +03:00
/*
2016-02-26 22:39:08 +03:00
* Return to vfs waitqueue , and back to service_operation
2018-05-12 00:11:48 +03:00
* through wait_for_matching_downcall .
2016-01-23 21:45:46 +03:00
*/
spin_lock ( & op - > lock ) ;
2016-02-19 02:53:41 +03:00
if ( unlikely ( op_is_cancel ( op ) ) ) {
2016-01-23 21:45:46 +03:00
spin_unlock ( & op - > lock ) ;
2016-02-12 07:07:19 +03:00
put_cancel ( op ) ;
2016-02-19 02:53:41 +03:00
} else if ( unlikely ( op_state_given_up ( op ) ) ) {
spin_unlock ( & op - > lock ) ;
2016-02-19 02:59:44 +03:00
complete ( & op - > waitq ) ;
2016-02-19 02:53:41 +03:00
} else {
set_op_state_serviced ( op ) ;
2016-03-03 21:46:48 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s: op:%s: op_state:%d: process:%s: \n " ,
__func__ ,
get_opname_string ( op ) ,
op - > op_state ,
current - > comm ) ;
2016-02-19 02:53:41 +03:00
spin_unlock ( & op - > lock ) ;
}
2016-01-13 19:18:12 +03:00
return ret ;
2016-01-23 03:47:47 +03:00
2016-02-19 02:53:41 +03:00
Efault :
op - > downcall . status = - ( ORANGEFS_ERROR_BIT | 9 ) ;
ret = - EFAULT ;
goto wakeup ;
Enomem :
op - > downcall . status = - ( ORANGEFS_ERROR_BIT | 8 ) ;
ret = - ENOMEM ;
goto wakeup ;
2015-07-17 17:38:12 +03:00
}
/*
* NOTE : gets called when the last reference to this device is dropped .
* Using the open_access_count variable , we enforce a reference count
* on this file so that it can be opened by only one process at a time .
* the devreq_mutex is used to make sure all i / o has completed
2015-11-24 23:12:14 +03:00
* before we call orangefs_bufmap_finalize , and similar such tricky
2015-07-17 17:38:12 +03:00
* situations
*/
2015-11-24 23:12:14 +03:00
static int orangefs_devreq_release ( struct inode * inode , struct file * file )
2015-07-17 17:38:12 +03:00
{
int unmounted = 0 ;
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s:pvfs2-client-core: exiting, closing device \n " ,
__func__ ) ;
mutex_lock ( & devreq_mutex ) ;
2016-02-14 05:01:21 +03:00
orangefs_bufmap_finalize ( ) ;
2015-07-17 17:38:12 +03:00
2016-01-23 03:46:08 +03:00
open_access_count = - 1 ;
2015-07-17 17:38:12 +03:00
unmounted = mark_all_pending_mounts ( ) ;
2015-11-24 23:12:14 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG , " ORANGEFS Device Close: Filesystem(s) %s \n " ,
2015-07-17 17:38:12 +03:00
( unmounted ? " UNMOUNTED " : " MOUNTED " ) ) ;
purge_waiting_ops ( ) ;
purge_inprogress_ops ( ) ;
2016-02-14 05:01:21 +03:00
orangefs_bufmap_run_down ( ) ;
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" pvfs2-client-core: device close complete \n " ) ;
2016-01-23 03:46:08 +03:00
open_access_count = 0 ;
2016-08-12 19:02:31 +03:00
orangefs_userspace_version = 0 ;
2016-01-23 03:46:08 +03:00
mutex_unlock ( & devreq_mutex ) ;
2015-07-17 17:38:12 +03:00
return 0 ;
}
int is_daemon_in_service ( void )
{
int in_service ;
/*
* What this function does is checks if client - core is alive
* based on the access count we maintain on the device .
*/
mutex_lock ( & devreq_mutex ) ;
in_service = open_access_count = = 1 ? 0 : - EIO ;
mutex_unlock ( & devreq_mutex ) ;
return in_service ;
}
2016-02-12 07:07:19 +03:00
bool __is_daemon_in_service ( void )
{
return open_access_count = = 1 ;
}
2015-07-17 17:38:12 +03:00
static inline long check_ioctl_command ( unsigned int command )
{
/* Check for valid ioctl codes */
2015-11-24 23:12:14 +03:00
if ( _IOC_TYPE ( command ) ! = ORANGEFS_DEV_MAGIC ) {
2015-07-17 17:38:12 +03:00
gossip_err ( " device ioctl magic numbers don't match! Did you rebuild pvfs2-client-core/libpvfs2? [cmd %x, magic %x != %x] \n " ,
command ,
_IOC_TYPE ( command ) ,
2015-11-24 23:12:14 +03:00
ORANGEFS_DEV_MAGIC ) ;
2015-07-17 17:38:12 +03:00
return - EINVAL ;
}
/* and valid ioctl commands */
2015-11-24 23:12:14 +03:00
if ( _IOC_NR ( command ) > = ORANGEFS_DEV_MAXNR | | _IOC_NR ( command ) < = 0 ) {
2015-07-17 17:38:12 +03:00
gossip_err ( " Invalid ioctl command number [%d >= %d] \n " ,
2015-11-24 23:12:14 +03:00
_IOC_NR ( command ) , ORANGEFS_DEV_MAXNR ) ;
2015-07-17 17:38:12 +03:00
return - ENOIOCTLCMD ;
}
return 0 ;
}
static long dispatch_ioctl_command ( unsigned int command , unsigned long arg )
{
2015-11-24 23:12:14 +03:00
static __s32 magic = ORANGEFS_DEVREQ_MAGIC ;
2015-12-15 22:22:06 +03:00
static __s32 max_up_size = MAX_DEV_REQ_UPSIZE ;
static __s32 max_down_size = MAX_DEV_REQ_DOWNSIZE ;
2015-11-24 23:12:14 +03:00
struct ORANGEFS_dev_map_desc user_desc ;
2015-07-17 17:38:12 +03:00
int ret = 0 ;
int upstream_kmod = 1 ;
2016-03-26 02:56:34 +03:00
struct orangefs_sb_info_s * orangefs_sb ;
2015-07-17 17:38:12 +03:00
/* mtmoore: add locking here */
switch ( command ) {
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_GET_MAGIC :
2015-07-17 17:38:12 +03:00
return ( ( put_user ( magic , ( __s32 __user * ) arg ) = = - EFAULT ) ?
- EIO :
0 ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_GET_MAX_UPSIZE :
2015-07-17 17:38:12 +03:00
return ( ( put_user ( max_up_size ,
( __s32 __user * ) arg ) = = - EFAULT ) ?
- EIO :
0 ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_GET_MAX_DOWNSIZE :
2015-07-17 17:38:12 +03:00
return ( ( put_user ( max_down_size ,
( __s32 __user * ) arg ) = = - EFAULT ) ?
- EIO :
0 ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_MAP :
2015-07-17 17:38:12 +03:00
ret = copy_from_user ( & user_desc ,
2015-11-24 23:12:14 +03:00
( struct ORANGEFS_dev_map_desc __user * )
2015-07-17 17:38:12 +03:00
arg ,
2015-11-24 23:12:14 +03:00
sizeof ( struct ORANGEFS_dev_map_desc ) ) ;
2016-02-14 05:01:21 +03:00
/* WTF -EIO and not -EFAULT? */
return ret ? - EIO : orangefs_bufmap_initialize ( & user_desc ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_REMOUNT_ALL :
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
" %s: got ORANGEFS_DEV_REMOUNT_ALL \n " ,
__func__ ) ;
2015-07-17 17:38:12 +03:00
/*
2015-11-24 23:12:14 +03:00
* remount all mounted orangefs volumes to regain the lost
2015-07-17 17:38:12 +03:00
* dynamic mount tables ( if any ) - - NOTE : this is done
* without keeping the superblock list locked due to the
2016-02-25 00:54:27 +03:00
* upcall / downcall waiting . also , the request mutex is
2015-07-17 17:38:12 +03:00
* used to ensure that no operations will be serviced until
* all of the remounts are serviced ( to avoid ops between
* mounts to fail )
*/
2016-08-16 18:38:14 +03:00
ret = mutex_lock_interruptible ( & orangefs_request_mutex ) ;
2015-07-17 17:38:12 +03:00
if ( ret < 0 )
return ret ;
gossip_debug ( GOSSIP_DEV_DEBUG ,
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
" %s: priority remount in progress \n " ,
__func__ ) ;
2016-03-26 02:56:34 +03:00
spin_lock ( & orangefs_superblocks_lock ) ;
list_for_each_entry ( orangefs_sb , & orangefs_superblocks , list ) {
/*
* We have to drop the spinlock , so entries can be
* removed . They can ' t be freed , though , so we just
* keep the forward pointers and zero the back ones -
* that way we can get to the rest of the list .
*/
if ( ! orangefs_sb - > list . prev )
continue ;
gossip_debug ( GOSSIP_DEV_DEBUG ,
" %s: Remounting SB %p \n " ,
__func__ ,
orangefs_sb ) ;
spin_unlock ( & orangefs_superblocks_lock ) ;
ret = orangefs_remount ( orangefs_sb ) ;
spin_lock ( & orangefs_superblocks_lock ) ;
if ( ret ) {
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
2016-03-26 02:56:34 +03:00
" SB %p remount failed \n " ,
2015-11-24 23:12:14 +03:00
orangefs_sb ) ;
2016-03-26 02:56:34 +03:00
break ;
2015-07-17 17:38:12 +03:00
}
}
2016-03-26 02:56:34 +03:00
spin_unlock ( & orangefs_superblocks_lock ) ;
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
Orangefs: de-uglify orangefs_devreq_writev, and devorangefs-req.c in general
AV dislikes many parts of orangefs_devreq_writev. Besides making
orangefs_devreq_writev more easily readable and better commented,
this patch makes an effort to address some of the problems:
> The 5th is quietly ignored unless trailer_size is positive and
> status is zero. If trailer_size > 0 && status == 0, you verify that
> the length of the 5th segment is no more than trailer_size and copy
> it to vmalloc'ed buffer. Without bothering to zero the rest of that
> buffer out.
It was just wrong to allow a 5th segment that is not exactly equal to
trailer_size. Now that that's fixed, there's nothing to zero out in
the vmalloced buffer - it is exactly the right size to hold the
5th segment.
> Another API bogosity: when the 5th segment is present, successful writev()
> returns the sum of sizes of the first 4.
Added size of 5th segment to writev return...
> if concatenation of the first 4 segments is longer than
> 16 + sizeof(struct pvfs2_downcall_s) by no more than sizeof(long) => whine
> and proceed with garbage.
If 4th segment isn't exactly sizeof(struct pvfs2_downcall_s), whine and fail.
> if the 32bit value 4 bytes into op->downcall is zero and 64bit
> value following it is non-zero, the latter is interpreted as the size of
> trailer data.
The latter is what userspace claimed was the length of the trailer data.
The kernel module now compares it to the trailer iovec's iov_len as a
sanity check.
> if there's no trailer, the 5th segment (if present) is completely ignored.
Whine and fail if there should be no trailer, yet a 5th segment is present.
> if vmalloc fails, act as if status (32bit at offset 5 into
> op->downcall) had been -ENOMEM and don't look at the 5th segment at all.
whine and fail with -ENOMEM.
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
2015-12-12 00:45:03 +03:00
" %s: priority remount complete \n " ,
__func__ ) ;
2016-08-16 18:38:14 +03:00
mutex_unlock ( & orangefs_request_mutex ) ;
2015-07-17 17:38:12 +03:00
return ret ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_UPSTREAM :
2015-07-17 17:38:12 +03:00
ret = copy_to_user ( ( void __user * ) arg ,
& upstream_kmod ,
sizeof ( upstream_kmod ) ) ;
if ( ret ! = 0 )
return - EIO ;
else
return ret ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_CLIENT_MASK :
2016-08-15 18:38:36 +03:00
return orangefs_debugfs_new_client_mask ( ( void __user * ) arg ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_CLIENT_STRING :
2016-08-15 18:38:36 +03:00
return orangefs_debugfs_new_client_string ( ( void __user * ) arg ) ;
2015-11-24 23:12:14 +03:00
case ORANGEFS_DEV_DEBUG :
2016-08-15 18:38:36 +03:00
return orangefs_debugfs_new_debug ( ( void __user * ) arg ) ;
2015-07-17 17:38:12 +03:00
default :
return - ENOIOCTLCMD ;
}
return - ENOIOCTLCMD ;
}
2015-11-24 23:12:14 +03:00
static long orangefs_devreq_ioctl ( struct file * file ,
2015-07-17 17:38:12 +03:00
unsigned int command , unsigned long arg )
{
long ret ;
/* Check for properly constructed commands */
ret = check_ioctl_command ( command ) ;
if ( ret < 0 )
return ( int ) ret ;
return ( int ) dispatch_ioctl_command ( command , arg ) ;
}
# ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
2015-11-24 23:12:14 +03:00
/* Compat structure for the ORANGEFS_DEV_MAP ioctl */
struct ORANGEFS_dev_map_desc32 {
2015-07-17 17:38:12 +03:00
compat_uptr_t ptr ;
__s32 total_size ;
__s32 size ;
__s32 count ;
} ;
/*
* 32 bit user - space apps ' ioctl handlers when kernel modules
* is compiled as a 64 bit one
*/
2015-11-24 23:12:14 +03:00
static long orangefs_devreq_compat_ioctl ( struct file * filp , unsigned int cmd ,
2015-07-17 17:38:12 +03:00
unsigned long args )
{
long ret ;
/* Check for properly constructed commands */
ret = check_ioctl_command ( cmd ) ;
if ( ret < 0 )
return ret ;
2015-11-24 23:12:14 +03:00
if ( cmd = = ORANGEFS_DEV_MAP ) {
2018-05-27 15:52:48 +03:00
struct ORANGEFS_dev_map_desc desc ;
struct ORANGEFS_dev_map_desc32 d32 ;
if ( copy_from_user ( & d32 , ( void __user * ) args , sizeof ( d32 ) ) )
return - EFAULT ;
desc . ptr = compat_ptr ( d32 . ptr ) ;
desc . total_size = d32 . total_size ;
desc . size = d32 . size ;
desc . count = d32 . count ;
return orangefs_bufmap_initialize ( & desc ) ;
2015-07-17 17:38:12 +03:00
}
/* no other ioctl requires translation */
2018-05-27 15:52:48 +03:00
return dispatch_ioctl_command ( cmd , args ) ;
2015-07-17 17:38:12 +03:00
}
2015-07-24 17:37:15 +03:00
# endif /* CONFIG_COMPAT is in .config */
2018-04-03 19:27:13 +03:00
static __poll_t orangefs_devreq_poll ( struct file * file ,
struct poll_table_struct * poll_table )
{
__poll_t poll_revent_mask = 0 ;
poll_wait ( file , & orangefs_request_list_waitq , poll_table ) ;
if ( ! list_empty ( & orangefs_request_list ) )
poll_revent_mask | = EPOLLIN ;
return poll_revent_mask ;
}
2015-07-17 17:38:12 +03:00
/* the assigned character device major number */
2015-11-24 23:12:14 +03:00
static int orangefs_dev_major ;
2015-07-17 17:38:12 +03:00
2018-04-03 19:27:13 +03:00
static const struct file_operations orangefs_devreq_file_operations = {
. owner = THIS_MODULE ,
. read = orangefs_devreq_read ,
. write_iter = orangefs_devreq_write_iter ,
. open = orangefs_devreq_open ,
. release = orangefs_devreq_release ,
. unlocked_ioctl = orangefs_devreq_ioctl ,
# ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
. compat_ioctl = orangefs_devreq_compat_ioctl ,
# endif
. poll = orangefs_devreq_poll
} ;
2015-07-17 17:38:12 +03:00
/*
2015-11-24 23:12:14 +03:00
* Initialize orangefs device specific state :
2015-07-17 17:38:12 +03:00
* Must be called at module load time only
*/
2015-11-24 23:12:14 +03:00
int orangefs_dev_init ( void )
2015-07-17 17:38:12 +03:00
{
2015-11-24 23:12:14 +03:00
/* register orangefs-req device */
orangefs_dev_major = register_chrdev ( 0 ,
ORANGEFS_REQDEVICE_NAME ,
& orangefs_devreq_file_operations ) ;
if ( orangefs_dev_major < 0 ) {
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" Failed to register /dev/%s (error %d) \n " ,
2015-11-24 23:12:14 +03:00
ORANGEFS_REQDEVICE_NAME , orangefs_dev_major ) ;
return orangefs_dev_major ;
2015-07-17 17:38:12 +03:00
}
gossip_debug ( GOSSIP_DEV_DEBUG ,
" *** /dev/%s character device registered *** \n " ,
2015-11-24 23:12:14 +03:00
ORANGEFS_REQDEVICE_NAME ) ;
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG , " 'mknod /dev/%s c %d 0'. \n " ,
2015-11-24 23:12:14 +03:00
ORANGEFS_REQDEVICE_NAME , orangefs_dev_major ) ;
2015-07-17 17:38:12 +03:00
return 0 ;
}
2015-11-24 23:12:14 +03:00
void orangefs_dev_cleanup ( void )
2015-07-17 17:38:12 +03:00
{
2015-11-24 23:12:14 +03:00
unregister_chrdev ( orangefs_dev_major , ORANGEFS_REQDEVICE_NAME ) ;
2015-07-17 17:38:12 +03:00
gossip_debug ( GOSSIP_DEV_DEBUG ,
" *** /dev/%s character device unregistered *** \n " ,
2015-11-24 23:12:14 +03:00
ORANGEFS_REQDEVICE_NAME ) ;
2015-07-17 17:38:12 +03:00
}