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
|
2014-09-11 08:37:27 +08:00
|
|
|
/*
|
2016-03-05 03:46:15 +08:00
|
|
|
* Copyright (c) 2014-2016 Christoph Hellwig.
|
2014-09-11 08:37:27 +08:00
|
|
|
*/
|
|
|
|
#include <linux/sunrpc/svc.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/nfs4.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include <linux/nfs_xdr.h>
|
2016-03-05 03:46:15 +08:00
|
|
|
#include <linux/pr.h>
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
#include "blocklayout.h"
|
|
|
|
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_PNFS_LD
|
|
|
|
|
|
|
|
static void
|
|
|
|
bl_free_device(struct pnfs_block_dev *dev)
|
|
|
|
{
|
|
|
|
if (dev->nr_children) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->nr_children; i++)
|
|
|
|
bl_free_device(&dev->children[i]);
|
|
|
|
kfree(dev->children);
|
|
|
|
} else {
|
2016-03-05 03:46:15 +08:00
|
|
|
if (dev->pr_registered) {
|
|
|
|
const struct pr_ops *ops =
|
|
|
|
dev->bdev->bd_disk->fops->pr_ops;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = ops->pr_register(dev->bdev, dev->pr_key, 0,
|
|
|
|
false);
|
|
|
|
if (error)
|
|
|
|
pr_err("failed to unregister PR key.\n");
|
|
|
|
}
|
|
|
|
|
2014-09-11 08:37:27 +08:00
|
|
|
if (dev->bdev)
|
2015-08-18 00:41:00 +08:00
|
|
|
blkdev_put(dev->bdev, FMODE_READ | FMODE_WRITE);
|
2014-09-11 08:37:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bl_free_deviceid_node(struct nfs4_deviceid_node *d)
|
|
|
|
{
|
|
|
|
struct pnfs_block_dev *dev =
|
|
|
|
container_of(d, struct pnfs_block_dev, node);
|
|
|
|
|
|
|
|
bl_free_device(dev);
|
2015-03-10 03:23:35 +08:00
|
|
|
kfree_rcu(dev, node.rcu);
|
2014-09-11 08:37:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfs4_block_decode_volume(struct xdr_stream *xdr, struct pnfs_block_volume *b)
|
|
|
|
{
|
|
|
|
__be32 *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
p = xdr_inline_decode(xdr, 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
b->type = be32_to_cpup(p++);
|
|
|
|
|
|
|
|
switch (b->type) {
|
|
|
|
case PNFS_BLOCK_VOLUME_SIMPLE:
|
|
|
|
p = xdr_inline_decode(xdr, 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
b->simple.nr_sigs = be32_to_cpup(p++);
|
2016-07-14 12:02:01 +08:00
|
|
|
if (!b->simple.nr_sigs || b->simple.nr_sigs > PNFS_BLOCK_MAX_UUIDS) {
|
|
|
|
dprintk("Bad signature count: %d\n", b->simple.nr_sigs);
|
2014-09-11 08:37:27 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->simple.len = 4 + 4;
|
|
|
|
for (i = 0; i < b->simple.nr_sigs; i++) {
|
|
|
|
p = xdr_inline_decode(xdr, 8 + 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
p = xdr_decode_hyper(p, &b->simple.sigs[i].offset);
|
|
|
|
b->simple.sigs[i].sig_len = be32_to_cpup(p++);
|
2015-08-18 00:40:59 +08:00
|
|
|
if (b->simple.sigs[i].sig_len > PNFS_BLOCK_UUID_LEN) {
|
|
|
|
pr_info("signature too long: %d\n",
|
|
|
|
b->simple.sigs[i].sig_len);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
p = xdr_inline_decode(xdr, b->simple.sigs[i].sig_len);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
memcpy(&b->simple.sigs[i].sig, p,
|
|
|
|
b->simple.sigs[i].sig_len);
|
|
|
|
|
2016-07-14 12:01:28 +08:00
|
|
|
b->simple.len += 8 + 4 + \
|
|
|
|
(XDR_QUADLEN(b->simple.sigs[i].sig_len) << 2);
|
2014-09-11 08:37:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PNFS_BLOCK_VOLUME_SLICE:
|
|
|
|
p = xdr_inline_decode(xdr, 8 + 8 + 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
p = xdr_decode_hyper(p, &b->slice.start);
|
|
|
|
p = xdr_decode_hyper(p, &b->slice.len);
|
|
|
|
b->slice.volume = be32_to_cpup(p++);
|
|
|
|
break;
|
|
|
|
case PNFS_BLOCK_VOLUME_CONCAT:
|
|
|
|
p = xdr_inline_decode(xdr, 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
2016-07-14 12:02:01 +08:00
|
|
|
|
2014-09-11 08:37:27 +08:00
|
|
|
b->concat.volumes_count = be32_to_cpup(p++);
|
2016-07-14 12:02:01 +08:00
|
|
|
if (b->concat.volumes_count > PNFS_BLOCK_MAX_DEVICES) {
|
|
|
|
dprintk("Too many volumes: %d\n", b->concat.volumes_count);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
p = xdr_inline_decode(xdr, b->concat.volumes_count * 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
for (i = 0; i < b->concat.volumes_count; i++)
|
|
|
|
b->concat.volumes[i] = be32_to_cpup(p++);
|
|
|
|
break;
|
|
|
|
case PNFS_BLOCK_VOLUME_STRIPE:
|
|
|
|
p = xdr_inline_decode(xdr, 8 + 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
2016-07-14 12:02:01 +08:00
|
|
|
|
2014-09-11 08:37:27 +08:00
|
|
|
p = xdr_decode_hyper(p, &b->stripe.chunk_size);
|
|
|
|
b->stripe.volumes_count = be32_to_cpup(p++);
|
2016-07-14 12:02:01 +08:00
|
|
|
if (b->stripe.volumes_count > PNFS_BLOCK_MAX_DEVICES) {
|
|
|
|
dprintk("Too many volumes: %d\n", b->stripe.volumes_count);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
p = xdr_inline_decode(xdr, b->stripe.volumes_count * 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
for (i = 0; i < b->stripe.volumes_count; i++)
|
|
|
|
b->stripe.volumes[i] = be32_to_cpup(p++);
|
|
|
|
break;
|
2016-03-05 03:46:15 +08:00
|
|
|
case PNFS_BLOCK_VOLUME_SCSI:
|
|
|
|
p = xdr_inline_decode(xdr, 4 + 4 + 4);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
b->scsi.code_set = be32_to_cpup(p++);
|
|
|
|
b->scsi.designator_type = be32_to_cpup(p++);
|
|
|
|
b->scsi.designator_len = be32_to_cpup(p++);
|
|
|
|
p = xdr_inline_decode(xdr, b->scsi.designator_len);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
if (b->scsi.designator_len > 256)
|
|
|
|
return -EIO;
|
|
|
|
memcpy(&b->scsi.designator, p, b->scsi.designator_len);
|
|
|
|
p = xdr_inline_decode(xdr, 8);
|
|
|
|
if (!p)
|
|
|
|
return -EIO;
|
|
|
|
p = xdr_decode_hyper(p, &b->scsi.pr_key);
|
|
|
|
break;
|
2014-09-11 08:37:27 +08:00
|
|
|
default:
|
|
|
|
dprintk("unknown volume type!\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset,
|
|
|
|
struct pnfs_block_dev_map *map)
|
|
|
|
{
|
|
|
|
map->start = dev->start;
|
|
|
|
map->len = dev->len;
|
|
|
|
map->disk_offset = dev->disk_offset;
|
|
|
|
map->bdev = dev->bdev;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bl_map_concat(struct pnfs_block_dev *dev, u64 offset,
|
|
|
|
struct pnfs_block_dev_map *map)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->nr_children; i++) {
|
|
|
|
struct pnfs_block_dev *child = &dev->children[i];
|
|
|
|
|
|
|
|
if (child->start > offset ||
|
|
|
|
child->start + child->len <= offset)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
child->map(child, offset - child->start, map);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintk("%s: ran off loop!\n", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bl_map_stripe(struct pnfs_block_dev *dev, u64 offset,
|
|
|
|
struct pnfs_block_dev_map *map)
|
|
|
|
{
|
|
|
|
struct pnfs_block_dev *child;
|
2014-09-19 05:03:46 +08:00
|
|
|
u64 chunk;
|
|
|
|
u32 chunk_idx;
|
2014-09-11 08:37:27 +08:00
|
|
|
u64 disk_offset;
|
|
|
|
|
2014-09-19 05:03:46 +08:00
|
|
|
chunk = div_u64(offset, dev->chunk_size);
|
|
|
|
div_u64_rem(chunk, dev->nr_children, &chunk_idx);
|
|
|
|
|
2018-07-04 17:59:58 +08:00
|
|
|
if (chunk_idx >= dev->nr_children) {
|
2014-09-11 08:37:27 +08:00
|
|
|
dprintk("%s: invalid chunk idx %d (%lld/%lld)\n",
|
|
|
|
__func__, chunk_idx, offset, dev->chunk_size);
|
|
|
|
/* error, should not happen */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truncate offset to the beginning of the stripe */
|
|
|
|
offset = chunk * dev->chunk_size;
|
|
|
|
|
|
|
|
/* disk offset of the stripe */
|
2014-09-19 05:03:46 +08:00
|
|
|
disk_offset = div_u64(offset, dev->nr_children);
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
child = &dev->children[chunk_idx];
|
|
|
|
child->map(child, disk_offset, map);
|
|
|
|
|
|
|
|
map->start += offset;
|
|
|
|
map->disk_offset += disk_offset;
|
|
|
|
map->len = dev->chunk_size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bl_parse_deviceid(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask);
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct pnfs_block_volume *v = &volumes[idx];
|
2016-07-21 19:32:04 +08:00
|
|
|
struct block_device *bdev;
|
2014-09-11 08:37:27 +08:00
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
dev = bl_resolve_deviceid(server, v, gfp_mask);
|
|
|
|
if (!dev)
|
|
|
|
return -EIO;
|
|
|
|
|
2016-07-21 19:32:04 +08:00
|
|
|
bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_WRITE, NULL);
|
|
|
|
if (IS_ERR(bdev)) {
|
2014-09-11 08:37:27 +08:00
|
|
|
printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
|
2016-07-21 19:32:04 +08:00
|
|
|
MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
|
|
|
|
return PTR_ERR(bdev);
|
2014-09-11 08:37:27 +08:00
|
|
|
}
|
2016-07-21 19:32:04 +08:00
|
|
|
d->bdev = bdev;
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
d->len = i_size_read(d->bdev->bd_inode);
|
|
|
|
d->map = bl_map_simple;
|
|
|
|
|
|
|
|
printk(KERN_INFO "pNFS: using block device %s\n",
|
|
|
|
d->bdev->bd_disk->disk_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-05 03:46:15 +08:00
|
|
|
static bool
|
|
|
|
bl_validate_designator(struct pnfs_block_volume *v)
|
|
|
|
{
|
|
|
|
switch (v->scsi.designator_type) {
|
|
|
|
case PS_DESIGNATOR_EUI64:
|
|
|
|
if (v->scsi.code_set != PS_CODE_SET_BINARY)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (v->scsi.designator_len != 8 &&
|
|
|
|
v->scsi.designator_len != 10 &&
|
|
|
|
v->scsi.designator_len != 16)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case PS_DESIGNATOR_NAA:
|
|
|
|
if (v->scsi.code_set != PS_CODE_SET_BINARY)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (v->scsi.designator_len != 8 &&
|
|
|
|
v->scsi.designator_len != 16)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case PS_DESIGNATOR_T10:
|
|
|
|
case PS_DESIGNATOR_NAME:
|
|
|
|
pr_err("pNFS: unsupported designator "
|
|
|
|
"(code set %d, type %d, len %d.\n",
|
|
|
|
v->scsi.code_set,
|
|
|
|
v->scsi.designator_type,
|
|
|
|
v->scsi.designator_len);
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
pr_err("pNFS: invalid designator "
|
|
|
|
"(code set %d, type %d, len %d.\n",
|
|
|
|
v->scsi.code_set,
|
|
|
|
v->scsi.designator_type,
|
|
|
|
v->scsi.designator_len);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:41:29 +08:00
|
|
|
/*
|
|
|
|
* Try to open the udev path for the WWN. At least on Debian the udev
|
|
|
|
* by-id path will always point to the dm-multipath device if one exists.
|
|
|
|
*/
|
|
|
|
static struct block_device *
|
|
|
|
bl_open_udev_path(struct pnfs_block_volume *v)
|
|
|
|
{
|
|
|
|
struct block_device *bdev;
|
|
|
|
const char *devname;
|
|
|
|
|
|
|
|
devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/wwn-0x%*phN",
|
|
|
|
v->scsi.designator_len, v->scsi.designator);
|
|
|
|
if (!devname)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
bdev = blkdev_get_by_path(devname, FMODE_READ | FMODE_WRITE, NULL);
|
|
|
|
if (IS_ERR(bdev)) {
|
|
|
|
pr_warn("pNFS: failed to open device %s (%ld)\n",
|
|
|
|
devname, PTR_ERR(bdev));
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(devname);
|
|
|
|
return bdev;
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:41:30 +08:00
|
|
|
/*
|
|
|
|
* Try to open the RH/Fedora specific dm-mpath udev path for this WWN, as the
|
|
|
|
* wwn- links will only point to the first discovered SCSI device there.
|
|
|
|
*/
|
|
|
|
static struct block_device *
|
|
|
|
bl_open_dm_mpath_udev_path(struct pnfs_block_volume *v)
|
|
|
|
{
|
|
|
|
struct block_device *bdev;
|
|
|
|
const char *devname;
|
|
|
|
|
|
|
|
devname = kasprintf(GFP_KERNEL,
|
|
|
|
"/dev/disk/by-id/dm-uuid-mpath-%d%*phN",
|
|
|
|
v->scsi.designator_type,
|
|
|
|
v->scsi.designator_len, v->scsi.designator);
|
|
|
|
if (!devname)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
bdev = blkdev_get_by_path(devname, FMODE_READ | FMODE_WRITE, NULL);
|
|
|
|
kfree(devname);
|
|
|
|
return bdev;
|
|
|
|
}
|
|
|
|
|
2016-03-05 03:46:15 +08:00
|
|
|
static int
|
|
|
|
bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct pnfs_block_volume *v = &volumes[idx];
|
2016-07-21 19:32:04 +08:00
|
|
|
struct block_device *bdev;
|
2016-03-05 03:46:15 +08:00
|
|
|
const struct pr_ops *ops;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!bl_validate_designator(v))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-07-21 19:32:04 +08:00
|
|
|
bdev = bl_open_dm_mpath_udev_path(v);
|
|
|
|
if (IS_ERR(bdev))
|
|
|
|
bdev = bl_open_udev_path(v);
|
|
|
|
if (IS_ERR(bdev))
|
|
|
|
return PTR_ERR(bdev);
|
|
|
|
d->bdev = bdev;
|
2016-03-05 03:46:15 +08:00
|
|
|
|
|
|
|
d->len = i_size_read(d->bdev->bd_inode);
|
|
|
|
d->map = bl_map_simple;
|
|
|
|
d->pr_key = v->scsi.pr_key;
|
|
|
|
|
|
|
|
pr_info("pNFS: using block device %s (reservation key 0x%llx)\n",
|
|
|
|
d->bdev->bd_disk->disk_name, d->pr_key);
|
|
|
|
|
|
|
|
ops = d->bdev->bd_disk->fops->pr_ops;
|
|
|
|
if (!ops) {
|
|
|
|
pr_err("pNFS: block device %s does not support reservations.",
|
|
|
|
d->bdev->bd_disk->disk_name);
|
|
|
|
error = -EINVAL;
|
|
|
|
goto out_blkdev_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ops->pr_register(d->bdev, 0, d->pr_key, true);
|
|
|
|
if (error) {
|
|
|
|
pr_err("pNFS: failed to register key for block device %s.",
|
|
|
|
d->bdev->bd_disk->disk_name);
|
|
|
|
goto out_blkdev_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->pr_registered = true;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_blkdev_put:
|
2016-07-08 17:41:28 +08:00
|
|
|
blkdev_put(d->bdev, FMODE_READ | FMODE_WRITE);
|
2016-03-05 03:46:15 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-09-11 08:37:27 +08:00
|
|
|
static int
|
|
|
|
bl_parse_slice(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct pnfs_block_volume *v = &volumes[idx];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = bl_parse_deviceid(server, d, volumes, v->slice.volume, gfp_mask);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
d->disk_offset = v->slice.start;
|
|
|
|
d->len = v->slice.len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bl_parse_concat(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct pnfs_block_volume *v = &volumes[idx];
|
|
|
|
u64 len = 0;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
d->children = kcalloc(v->concat.volumes_count,
|
|
|
|
sizeof(struct pnfs_block_dev), GFP_KERNEL);
|
|
|
|
if (!d->children)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < v->concat.volumes_count; i++) {
|
|
|
|
ret = bl_parse_deviceid(server, &d->children[i],
|
|
|
|
volumes, v->concat.volumes[i], gfp_mask);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
d->nr_children++;
|
|
|
|
d->children[i].start += len;
|
|
|
|
len += d->children[i].len;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->len = len;
|
|
|
|
d->map = bl_map_concat;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bl_parse_stripe(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct pnfs_block_volume *v = &volumes[idx];
|
|
|
|
u64 len = 0;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
d->children = kcalloc(v->stripe.volumes_count,
|
|
|
|
sizeof(struct pnfs_block_dev), GFP_KERNEL);
|
|
|
|
if (!d->children)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < v->stripe.volumes_count; i++) {
|
|
|
|
ret = bl_parse_deviceid(server, &d->children[i],
|
|
|
|
volumes, v->stripe.volumes[i], gfp_mask);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
d->nr_children++;
|
|
|
|
len += d->children[i].len;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->len = len;
|
|
|
|
d->chunk_size = v->stripe.chunk_size;
|
|
|
|
d->map = bl_map_stripe;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bl_parse_deviceid(struct nfs_server *server, struct pnfs_block_dev *d,
|
|
|
|
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
switch (volumes[idx].type) {
|
|
|
|
case PNFS_BLOCK_VOLUME_SIMPLE:
|
|
|
|
return bl_parse_simple(server, d, volumes, idx, gfp_mask);
|
|
|
|
case PNFS_BLOCK_VOLUME_SLICE:
|
|
|
|
return bl_parse_slice(server, d, volumes, idx, gfp_mask);
|
|
|
|
case PNFS_BLOCK_VOLUME_CONCAT:
|
|
|
|
return bl_parse_concat(server, d, volumes, idx, gfp_mask);
|
|
|
|
case PNFS_BLOCK_VOLUME_STRIPE:
|
|
|
|
return bl_parse_stripe(server, d, volumes, idx, gfp_mask);
|
2016-03-05 03:46:15 +08:00
|
|
|
case PNFS_BLOCK_VOLUME_SCSI:
|
|
|
|
return bl_parse_scsi(server, d, volumes, idx, gfp_mask);
|
2014-09-11 08:37:27 +08:00
|
|
|
default:
|
|
|
|
dprintk("unsupported volume type: %d\n", volumes[idx].type);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nfs4_deviceid_node *
|
|
|
|
bl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
|
|
|
|
gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *node = NULL;
|
|
|
|
struct pnfs_block_volume *volumes;
|
|
|
|
struct pnfs_block_dev *top;
|
|
|
|
struct xdr_stream xdr;
|
|
|
|
struct xdr_buf buf;
|
|
|
|
struct page *scratch;
|
|
|
|
int nr_volumes, ret, i;
|
|
|
|
__be32 *p;
|
|
|
|
|
|
|
|
scratch = alloc_page(gfp_mask);
|
|
|
|
if (!scratch)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
xdr_init_decode_pages(&xdr, &buf, pdev->pages, pdev->pglen);
|
|
|
|
xdr_set_scratch_buffer(&xdr, page_address(scratch), PAGE_SIZE);
|
|
|
|
|
|
|
|
p = xdr_inline_decode(&xdr, sizeof(__be32));
|
|
|
|
if (!p)
|
|
|
|
goto out_free_scratch;
|
|
|
|
nr_volumes = be32_to_cpup(p++);
|
|
|
|
|
|
|
|
volumes = kcalloc(nr_volumes, sizeof(struct pnfs_block_volume),
|
|
|
|
gfp_mask);
|
|
|
|
if (!volumes)
|
|
|
|
goto out_free_scratch;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_volumes; i++) {
|
|
|
|
ret = nfs4_block_decode_volume(&xdr, &volumes[i]);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_free_volumes;
|
|
|
|
}
|
|
|
|
|
|
|
|
top = kzalloc(sizeof(*top), gfp_mask);
|
|
|
|
if (!top)
|
|
|
|
goto out_free_volumes;
|
|
|
|
|
|
|
|
ret = bl_parse_deviceid(server, top, volumes, nr_volumes - 1, gfp_mask);
|
|
|
|
|
|
|
|
node = &top->node;
|
|
|
|
nfs4_init_deviceid_node(node, server, &pdev->dev_id);
|
pnfs/blocklayout: handle transient devices
PNFS block/SCSI layouts should gracefully handle cases where block devices
are not available when a layout is retrieved, or the block devices are
removed while the client holds a layout.
While setting up a layout segment, keep a record of an unavailable or
un-parsable block device in cache with a flag so that subsequent layouts do
not spam the server with GETDEVINFO. We can reuse the current
NFS_DEVICEID_UNAVAILABLE handling with one variation: instead of reusing
the device, we will discard it and send a fresh GETDEVINFO after the
timeout, since the lookup and validation of the device occurs within the
GETDEVINFO response handling.
A lookup of a layout segment that references an unavailable device will
return a segment with the NFS_LSEG_UNAVAILABLE flag set. This will allow
the pgio layer to mark the layout with the appropriate fail bit, which
forces subsequent IO to the MDS, and prevents spamming the server with
LAYOUTGET, LAYOUTRETURN.
Finally, when IO to a block device fails, look up the block device(s)
referenced by the pgio header, and mark them as unavailable.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
2017-12-09 01:52:59 +08:00
|
|
|
if (ret)
|
|
|
|
nfs4_mark_deviceid_unavailable(node);
|
2014-09-11 08:37:27 +08:00
|
|
|
|
|
|
|
out_free_volumes:
|
|
|
|
kfree(volumes);
|
|
|
|
out_free_scratch:
|
|
|
|
__free_page(scratch);
|
|
|
|
out:
|
|
|
|
return node;
|
|
|
|
}
|