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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/scsi/scsi_proc.c
|
|
|
|
*
|
|
|
|
* The functions in this file provide an interface between
|
|
|
|
* the PROC file system and the SCSI device drivers
|
|
|
|
* It is mainly used for debugging, statistics and to pass
|
|
|
|
* information directly to the lowlevel driver.
|
|
|
|
*
|
|
|
|
* (c) 1995 Michael Neuffer neuffer@goofy.zdv.uni-mainz.de
|
|
|
|
* Version: 0.99.8 last change: 95/09/13
|
|
|
|
*
|
|
|
|
* generic command parser provided by:
|
|
|
|
* Andreas Heilwagen <crashcar@informatik.uni-koblenz.de>
|
|
|
|
*
|
|
|
|
* generic_proc_info() support of xxxx_info() by:
|
|
|
|
* Michael A. Griffith <grif@acm.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/seq_file.h>
|
2006-01-11 20:16:10 +08:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
2006-01-14 02:04:00 +08:00
|
|
|
#include <scsi/scsi_transport.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "scsi_priv.h"
|
|
|
|
#include "scsi_logging.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* 4K page size, but our output routines, use some slack for overruns */
|
|
|
|
#define PROC_BLOCK_SIZE (3*1024)
|
|
|
|
|
|
|
|
static struct proc_dir_entry *proc_scsi;
|
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
/* Protects scsi_proc_list */
|
2006-01-11 20:16:10 +08:00
|
|
|
static DEFINE_MUTEX(global_host_template_mutex);
|
2022-10-15 08:24:14 +08:00
|
|
|
static LIST_HEAD(scsi_proc_list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct scsi_proc_entry - (host template, SCSI proc dir) association
|
|
|
|
* @entry: entry in scsi_proc_list.
|
|
|
|
* @sht: SCSI host template associated with the procfs directory.
|
|
|
|
* @proc_dir: procfs directory associated with the SCSI host template.
|
|
|
|
* @present: Number of SCSI hosts instantiated for @sht.
|
|
|
|
*/
|
|
|
|
struct scsi_proc_entry {
|
|
|
|
struct list_head entry;
|
|
|
|
const struct scsi_host_template *sht;
|
|
|
|
struct proc_dir_entry *proc_dir;
|
|
|
|
unsigned int present;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-03-31 11:58:05 +08:00
|
|
|
static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2022-01-22 14:14:23 +08:00
|
|
|
struct Scsi_Host *shost = pde_data(file_inode(file));
|
2013-03-31 11:58:05 +08:00
|
|
|
ssize_t ret = -ENOMEM;
|
|
|
|
char *page;
|
|
|
|
|
|
|
|
if (count > PROC_BLOCK_SIZE)
|
|
|
|
return -EOVERFLOW;
|
|
|
|
|
|
|
|
if (!shost->hostt->write_info)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
page = (char *)__get_free_page(GFP_KERNEL);
|
|
|
|
if (page) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
if (copy_from_user(page, buf, count))
|
|
|
|
goto out;
|
|
|
|
ret = shost->hostt->write_info(shost, page, count);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
free_page((unsigned long)page);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_scsi_show(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = m->private;
|
|
|
|
return shost->hostt->show_info(m, shost);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_scsi_host_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2022-01-22 14:14:23 +08:00
|
|
|
return single_open_size(file, proc_scsi_show, pde_data(inode),
|
2013-04-01 01:50:52 +08:00
|
|
|
4 * PAGE_SIZE);
|
2013-03-31 11:58:05 +08:00
|
|
|
}
|
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
static struct scsi_proc_entry *
|
|
|
|
__scsi_lookup_proc_entry(const struct scsi_host_template *sht)
|
|
|
|
{
|
|
|
|
struct scsi_proc_entry *e;
|
|
|
|
|
|
|
|
lockdep_assert_held(&global_host_template_mutex);
|
|
|
|
|
|
|
|
list_for_each_entry(e, &scsi_proc_list, entry)
|
|
|
|
if (e->sht == sht)
|
|
|
|
return e;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct scsi_proc_entry *
|
|
|
|
scsi_lookup_proc_entry(const struct scsi_host_template *sht)
|
|
|
|
{
|
|
|
|
struct scsi_proc_entry *e;
|
|
|
|
|
|
|
|
mutex_lock(&global_host_template_mutex);
|
|
|
|
e = __scsi_lookup_proc_entry(sht);
|
|
|
|
mutex_unlock(&global_host_template_mutex);
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2022-10-15 08:24:12 +08:00
|
|
|
/**
|
|
|
|
* scsi_template_proc_dir() - returns the procfs dir for a SCSI host template
|
|
|
|
* @sht: SCSI host template pointer.
|
|
|
|
*/
|
|
|
|
struct proc_dir_entry *
|
|
|
|
scsi_template_proc_dir(const struct scsi_host_template *sht)
|
|
|
|
{
|
2022-10-15 08:24:14 +08:00
|
|
|
struct scsi_proc_entry *e = scsi_lookup_proc_entry(sht);
|
|
|
|
|
|
|
|
return e ? e->proc_dir : NULL;
|
2022-10-15 08:24:12 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(scsi_template_proc_dir);
|
|
|
|
|
2020-02-04 09:37:17 +08:00
|
|
|
static const struct proc_ops proc_scsi_ops = {
|
|
|
|
.proc_open = proc_scsi_host_open,
|
|
|
|
.proc_release = single_release,
|
|
|
|
.proc_read = seq_read,
|
|
|
|
.proc_lseek = seq_lseek,
|
|
|
|
.proc_write = proc_scsi_host_write
|
2013-03-31 11:58:05 +08:00
|
|
|
};
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_proc_hostdir_add - Create directory in /proc for a scsi host
|
|
|
|
* @sht: owner of this directory
|
|
|
|
*
|
|
|
|
* Sets sht->proc_dir to the new directory.
|
|
|
|
*/
|
2022-10-15 08:24:14 +08:00
|
|
|
int scsi_proc_hostdir_add(const struct scsi_host_template *sht)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2022-10-15 08:24:14 +08:00
|
|
|
struct scsi_proc_entry *e;
|
|
|
|
int ret;
|
2022-10-15 08:24:13 +08:00
|
|
|
|
2013-04-01 01:27:56 +08:00
|
|
|
if (!sht->show_info)
|
2022-10-15 08:24:13 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_lock(&global_host_template_mutex);
|
2022-10-15 08:24:14 +08:00
|
|
|
e = __scsi_lookup_proc_entry(sht);
|
|
|
|
if (!e) {
|
|
|
|
e = kzalloc(sizeof(*e), GFP_KERNEL);
|
|
|
|
if (!e) {
|
2022-10-15 08:24:13 +08:00
|
|
|
ret = -ENOMEM;
|
2022-10-15 08:24:14 +08:00
|
|
|
goto unlock;
|
2022-10-15 08:24:13 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2022-10-15 08:24:14 +08:00
|
|
|
if (e->present++)
|
|
|
|
goto success;
|
|
|
|
e->proc_dir = proc_mkdir(sht->proc_name, proc_scsi);
|
|
|
|
if (!e->proc_dir) {
|
|
|
|
printk(KERN_ERR "%s: proc_mkdir failed for %s\n", __func__,
|
|
|
|
sht->proc_name);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
e->sht = sht;
|
|
|
|
list_add_tail(&e->entry, &scsi_proc_list);
|
|
|
|
success:
|
|
|
|
e = NULL;
|
|
|
|
ret = 0;
|
|
|
|
unlock:
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_unlock(&global_host_template_mutex);
|
2022-10-15 08:24:13 +08:00
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
kfree(e);
|
2022-10-15 08:24:13 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_proc_hostdir_rm - remove directory in /proc for a scsi host
|
|
|
|
* @sht: owner of directory
|
|
|
|
*/
|
2022-10-15 08:24:14 +08:00
|
|
|
void scsi_proc_hostdir_rm(const struct scsi_host_template *sht)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2022-10-15 08:24:14 +08:00
|
|
|
struct scsi_proc_entry *e;
|
|
|
|
|
2013-04-01 01:27:56 +08:00
|
|
|
if (!sht->show_info)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_lock(&global_host_template_mutex);
|
2022-10-15 08:24:14 +08:00
|
|
|
e = __scsi_lookup_proc_entry(sht);
|
|
|
|
if (e && !--e->present) {
|
2005-04-17 06:20:36 +08:00
|
|
|
remove_proc_entry(sht->proc_name, proc_scsi);
|
2022-10-15 08:24:14 +08:00
|
|
|
list_del(&e->entry);
|
|
|
|
kfree(e);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_unlock(&global_host_template_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_proc_host_add - Add entry for this host to appropriate /proc dir
|
|
|
|
* @shost: host to add
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
void scsi_proc_host_add(struct Scsi_Host *shost)
|
|
|
|
{
|
2022-10-15 08:24:14 +08:00
|
|
|
const struct scsi_host_template *sht = shost->hostt;
|
|
|
|
struct scsi_proc_entry *e;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct proc_dir_entry *p;
|
|
|
|
char name[10];
|
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
if (!sht->show_info)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
e = scsi_lookup_proc_entry(sht);
|
|
|
|
if (!e)
|
|
|
|
goto err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
sprintf(name,"%d", shost->host_no);
|
2022-10-15 08:24:14 +08:00
|
|
|
p = proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir,
|
|
|
|
&proc_scsi_ops, shost);
|
2013-04-01 01:27:56 +08:00
|
|
|
if (!p)
|
2022-10-15 08:24:14 +08:00
|
|
|
goto err;
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
shost_printk(KERN_ERR, shost,
|
|
|
|
"%s: Failed to register host (%s failed)\n", __func__,
|
|
|
|
e ? "proc_create_data()" : "scsi_proc_hostdir_add()");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_proc_host_rm - remove this host's entry from /proc
|
|
|
|
* @shost: which host
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
void scsi_proc_host_rm(struct Scsi_Host *shost)
|
|
|
|
{
|
2022-10-15 08:24:14 +08:00
|
|
|
const struct scsi_host_template *sht = shost->hostt;
|
|
|
|
struct scsi_proc_entry *e;
|
2005-04-17 06:20:36 +08:00
|
|
|
char name[10];
|
|
|
|
|
2022-10-15 08:24:14 +08:00
|
|
|
if (!sht->show_info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
e = scsi_lookup_proc_entry(sht);
|
|
|
|
if (!e)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
sprintf(name,"%d", shost->host_no);
|
2022-10-15 08:24:14 +08:00
|
|
|
remove_proc_entry(name, e->proc_dir);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* proc_print_scsidevice - return data about this host
|
|
|
|
* @dev: A scsi device
|
|
|
|
* @data: &struct seq_file to output to.
|
|
|
|
*
|
|
|
|
* Description: prints Host, Channel, Id, Lun, Vendor, Model, Rev, Type,
|
|
|
|
* and revision.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int proc_print_scsidevice(struct device *dev, void *data)
|
|
|
|
{
|
2008-03-18 21:32:28 +08:00
|
|
|
struct scsi_device *sdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct seq_file *s = data;
|
|
|
|
int i;
|
|
|
|
|
2008-03-18 21:32:28 +08:00
|
|
|
if (!scsi_is_sdev_device(dev))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sdev = to_scsi_device(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
seq_printf(s,
|
2014-06-25 21:27:36 +08:00
|
|
|
"Host: scsi%d Channel: %02d Id: %02d Lun: %02llu\n Vendor: ",
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (sdev->vendor[i] >= 0x20)
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_putc(s, sdev->vendor[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2014-12-03 07:10:54 +08:00
|
|
|
seq_putc(s, ' ');
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_puts(s, " Model: ");
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if (sdev->model[i] >= 0x20)
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_putc(s, sdev->model[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2014-12-03 07:10:54 +08:00
|
|
|
seq_putc(s, ' ');
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_puts(s, " Rev: ");
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (sdev->rev[i] >= 0x20)
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_putc(s, sdev->rev[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2014-12-03 07:10:54 +08:00
|
|
|
seq_putc(s, ' ');
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-12-03 07:10:54 +08:00
|
|
|
seq_putc(s, '\n');
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-05 02:15:20 +08:00
|
|
|
seq_printf(s, " Type: %s ", scsi_device_type(sdev->type));
|
2007-01-09 00:07:41 +08:00
|
|
|
seq_printf(s, " ANSI SCSI revision: %02x",
|
|
|
|
sdev->scsi_level - (sdev->scsi_level > 1));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sdev->scsi_level == 2)
|
2014-12-03 07:10:52 +08:00
|
|
|
seq_puts(s, " CCS\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2014-12-03 07:10:54 +08:00
|
|
|
seq_putc(s, '\n');
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-18 21:32:28 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_add_single_device - Respond to user request to probe for/add device
|
|
|
|
* @host: user-supplied decimal integer
|
|
|
|
* @channel: user-supplied decimal integer
|
|
|
|
* @id: user-supplied decimal integer
|
|
|
|
* @lun: user-supplied decimal integer
|
|
|
|
*
|
|
|
|
* Description: called by writing "scsi add-single-device" to /proc/scsi/scsi.
|
|
|
|
*
|
|
|
|
* does scsi_host_lookup() and either user_scan() if that transport
|
|
|
|
* type supports it, or else scsi_scan_host_selected()
|
|
|
|
*
|
|
|
|
* Note: this seems to be aimed exclusively at SCSI parallel busses.
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *shost;
|
|
|
|
int error = -ENXIO;
|
|
|
|
|
|
|
|
shost = scsi_host_lookup(host);
|
2008-08-08 08:49:30 +08:00
|
|
|
if (!shost)
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-14 02:04:00 +08:00
|
|
|
if (shost->transportt->user_scan)
|
|
|
|
error = shost->transportt->user_scan(shost, channel, id, lun);
|
|
|
|
else
|
2016-03-17 15:39:45 +08:00
|
|
|
error = scsi_scan_host_selected(shost, channel, id, lun,
|
|
|
|
SCSI_SCAN_MANUAL);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_host_put(shost);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_remove_single_device - Respond to user request to remove a device
|
|
|
|
* @host: user-supplied decimal integer
|
|
|
|
* @channel: user-supplied decimal integer
|
|
|
|
* @id: user-supplied decimal integer
|
|
|
|
* @lun: user-supplied decimal integer
|
|
|
|
*
|
|
|
|
* Description: called by writing "scsi remove-single-device" to
|
|
|
|
* /proc/scsi/scsi. Does a scsi_device_lookup() and scsi_remove_device()
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
struct Scsi_Host *shost;
|
|
|
|
int error = -ENXIO;
|
|
|
|
|
|
|
|
shost = scsi_host_lookup(host);
|
2008-08-08 08:49:30 +08:00
|
|
|
if (!shost)
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev = scsi_device_lookup(shost, channel, id, lun);
|
|
|
|
if (sdev) {
|
|
|
|
scsi_remove_device(sdev);
|
|
|
|
scsi_device_put(sdev);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
scsi_host_put(shost);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* proc_scsi_write - handle writes to /proc/scsi/scsi
|
|
|
|
* @file: not used
|
|
|
|
* @buf: buffer to write
|
|
|
|
* @length: length of buf, at most PAGE_SIZE
|
|
|
|
* @ppos: not used
|
|
|
|
*
|
|
|
|
* Description: this provides a legacy mechanism to add or remove devices by
|
|
|
|
* Host, Channel, ID, and Lun. To use,
|
|
|
|
* "echo 'scsi add-single-device 0 1 2 3' > /proc/scsi/scsi" or
|
|
|
|
* "echo 'scsi remove-single-device 0 1 2 3' > /proc/scsi/scsi" with
|
|
|
|
* "0 1 2 3" replaced by the Host, Channel, Id, and Lun.
|
|
|
|
*
|
|
|
|
* Note: this seems to be aimed at parallel SCSI. Most modern busses (USB,
|
|
|
|
* SATA, Firewire, Fibre Channel, etc) dynamically assign these values to
|
|
|
|
* provide a unique identifier and nothing more.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
|
|
|
|
size_t length, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int host, channel, id, lun;
|
2023-07-25 02:25:40 +08:00
|
|
|
char *buffer, *end, *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!buf || length > PAGE_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
buffer = (char *)__get_free_page(GFP_KERNEL);
|
|
|
|
if (!buffer)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = -EFAULT;
|
|
|
|
if (copy_from_user(buffer, buf, length))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -EINVAL;
|
2023-07-25 02:25:40 +08:00
|
|
|
if (length < PAGE_SIZE) {
|
|
|
|
end = buffer + length;
|
|
|
|
*end = '\0';
|
|
|
|
} else {
|
|
|
|
end = buffer + PAGE_SIZE - 1;
|
|
|
|
if (*end)
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Usage: echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
|
|
|
|
* with "0 1 2 3" replaced by your "Host Channel Id Lun".
|
|
|
|
*/
|
|
|
|
if (!strncmp("scsi add-single-device", buffer, 22)) {
|
|
|
|
p = buffer + 23;
|
|
|
|
|
2023-07-25 02:25:40 +08:00
|
|
|
host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
|
|
|
|
channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
|
|
|
id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
|
|
|
lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = scsi_add_single_device(host, channel, id, lun);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usage: echo "scsi remove-single-device 0 1 2 3" >/proc/scsi/scsi
|
|
|
|
* with "0 1 2 3" replaced by your "Host Channel Id Lun".
|
|
|
|
*/
|
|
|
|
} else if (!strncmp("scsi remove-single-device", buffer, 25)) {
|
|
|
|
p = buffer + 26;
|
|
|
|
|
2023-07-25 02:25:40 +08:00
|
|
|
host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
|
|
|
|
channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
|
|
|
id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
|
|
|
lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = scsi_remove_single_device(host, channel, id, lun);
|
|
|
|
}
|
|
|
|
|
2006-04-28 03:07:49 +08:00
|
|
|
/*
|
|
|
|
* convert success returns so that we return the
|
|
|
|
* number of bytes consumed.
|
|
|
|
*/
|
|
|
|
if (!err)
|
|
|
|
err = length;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
free_page((unsigned long)buffer);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-04-28 04:22:20 +08:00
|
|
|
static inline struct device *next_scsi_device(struct device *start)
|
|
|
|
{
|
2019-07-24 06:18:37 +08:00
|
|
|
struct device *next = bus_find_next_device(&scsi_bus_type, start);
|
|
|
|
|
2011-04-28 04:22:20 +08:00
|
|
|
put_device(start);
|
|
|
|
return next;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 04:22:20 +08:00
|
|
|
static void *scsi_seq_start(struct seq_file *sfile, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct device *dev = NULL;
|
|
|
|
loff_t n = *pos;
|
|
|
|
|
|
|
|
while ((dev = next_scsi_device(dev))) {
|
|
|
|
if (!n--)
|
|
|
|
break;
|
|
|
|
sfile->private++;
|
|
|
|
}
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *scsi_seq_next(struct seq_file *sfile, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
(*pos)++;
|
|
|
|
sfile->private++;
|
|
|
|
return next_scsi_device(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void scsi_seq_stop(struct seq_file *sfile, void *v)
|
|
|
|
{
|
|
|
|
put_device(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int scsi_seq_show(struct seq_file *sfile, void *dev)
|
|
|
|
{
|
|
|
|
if (!sfile->private)
|
|
|
|
seq_puts(sfile, "Attached devices:\n");
|
|
|
|
|
|
|
|
return proc_print_scsidevice(dev, sfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct seq_operations scsi_seq_ops = {
|
|
|
|
.start = scsi_seq_start,
|
|
|
|
.next = scsi_seq_next,
|
|
|
|
.stop = scsi_seq_stop,
|
|
|
|
.show = scsi_seq_show
|
|
|
|
};
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* proc_scsi_open - glue function
|
|
|
|
* @inode: not used
|
|
|
|
* @file: passed to single_open()
|
|
|
|
*
|
|
|
|
* Associates proc_scsi_show with this file
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int proc_scsi_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
/*
|
2007-11-04 02:30:39 +08:00
|
|
|
* We don't really need this for the write case but it doesn't
|
2005-04-17 06:20:36 +08:00
|
|
|
* harm either.
|
|
|
|
*/
|
2011-04-28 04:22:20 +08:00
|
|
|
return seq_open(file, &scsi_seq_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-02-04 09:37:17 +08:00
|
|
|
static const struct proc_ops scsi_scsi_proc_ops = {
|
|
|
|
.proc_open = proc_scsi_open,
|
|
|
|
.proc_read = seq_read,
|
|
|
|
.proc_write = proc_scsi_write,
|
|
|
|
.proc_lseek = seq_lseek,
|
|
|
|
.proc_release = seq_release,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_init_procfs - create scsi and scsi/scsi in procfs
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int __init scsi_init_procfs(void)
|
|
|
|
{
|
|
|
|
struct proc_dir_entry *pde;
|
|
|
|
|
|
|
|
proc_scsi = proc_mkdir("scsi", NULL);
|
|
|
|
if (!proc_scsi)
|
|
|
|
goto err1;
|
|
|
|
|
2020-02-04 09:37:17 +08:00
|
|
|
pde = proc_create("scsi/scsi", 0, NULL, &scsi_scsi_proc_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!pde)
|
|
|
|
goto err2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err2:
|
|
|
|
remove_proc_entry("scsi", NULL);
|
|
|
|
err1:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2007-11-04 02:30:39 +08:00
|
|
|
/**
|
|
|
|
* scsi_exit_procfs - Remove scsi/scsi and scsi from procfs
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
void scsi_exit_procfs(void)
|
|
|
|
{
|
|
|
|
remove_proc_entry("scsi/scsi", NULL);
|
|
|
|
remove_proc_entry("scsi", NULL);
|
|
|
|
}
|