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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-07-17 14:38:12 +00:00
|
|
|
/*
|
2017-04-25 19:37:59 +00:00
|
|
|
* Copyright 2017 Omnibond Systems, L.L.C.
|
2015-07-17 14:38:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "protocol.h"
|
2015-12-04 17:56:14 +00:00
|
|
|
#include "orangefs-kernel.h"
|
|
|
|
#include "orangefs-bufmap.h"
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:38:01 +00:00
|
|
|
struct orangefs_dir_part {
|
|
|
|
struct orangefs_dir_part *next;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct orangefs_dir {
|
|
|
|
__u64 token;
|
|
|
|
struct orangefs_dir_part *part;
|
|
|
|
loff_t end;
|
|
|
|
int error;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PART_SHIFT (24)
|
|
|
|
#define PART_SIZE (1<<24)
|
|
|
|
#define PART_MASK (~(PART_SIZE - 1))
|
|
|
|
|
2015-07-17 14:38:12 +00:00
|
|
|
/*
|
2017-04-25 19:37:59 +00:00
|
|
|
* There can be up to 512 directory entries. Each entry is encoded as
|
|
|
|
* follows:
|
|
|
|
* 4 bytes: string size (n)
|
|
|
|
* n bytes: string
|
|
|
|
* 1 byte: trailing zero
|
|
|
|
* padding to 8 bytes
|
|
|
|
* 16 bytes: khandle
|
|
|
|
* padding to 8 bytes
|
|
|
|
*
|
|
|
|
* The trailer_buf starts with a struct orangefs_readdir_response_s
|
|
|
|
* which must be skipped to get to the directory data.
|
2017-04-25 19:38:01 +00:00
|
|
|
*
|
|
|
|
* The data which is received from the userspace daemon is termed a
|
|
|
|
* part and is stored in a linked list in case more than one part is
|
|
|
|
* needed for a large directory.
|
|
|
|
*
|
|
|
|
* The position pointer (ctx->pos) encodes the part and offset on which
|
|
|
|
* to begin reading at. Bits above PART_SHIFT encode the part and bits
|
|
|
|
* below PART_SHIFT encode the offset. Parts are stored in a linked
|
|
|
|
* list which grows as data is received from the server. The overhead
|
|
|
|
* associated with managing the list is presumed to be small compared to
|
|
|
|
* the overhead of communicating with the server.
|
|
|
|
*
|
|
|
|
* As data is received from the server, it is placed at the end of the
|
|
|
|
* part list. Data is parsed from the current position as it is needed.
|
|
|
|
* When data is determined to be corrupt, it is either because the
|
|
|
|
* userspace component has sent back corrupt data or because the file
|
|
|
|
* pointer has been moved to an invalid location. Since the two cannot
|
|
|
|
* be differentiated, return EIO.
|
|
|
|
*
|
|
|
|
* Part zero is synthesized to contains `.' and `..'. Part one is the
|
|
|
|
* first part of the part list.
|
2015-07-17 14:38:12 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-20 19:36:12 +00:00
|
|
|
static int do_readdir(struct orangefs_dir *od, struct inode *inode,
|
2017-04-25 19:38:01 +00:00
|
|
|
struct orangefs_kernel_op_s *op)
|
2017-04-25 19:37:59 +00:00
|
|
|
{
|
2023-04-20 19:36:12 +00:00
|
|
|
struct orangefs_inode_s *oi = ORANGEFS_I(inode);
|
2017-04-25 19:37:59 +00:00
|
|
|
struct orangefs_readdir_response_s *resp;
|
|
|
|
int bufi, r;
|
|
|
|
|
2016-02-17 17:55:42 +00:00
|
|
|
/*
|
2017-04-25 19:37:59 +00:00
|
|
|
* Despite the badly named field, readdir does not use shared
|
|
|
|
* memory. However, there are a limited number of readdir
|
|
|
|
* slots, which must be allocated here. This flag simply tells
|
|
|
|
* the op scheduler to return the op here for retry.
|
2016-02-17 17:55:42 +00:00
|
|
|
*/
|
2017-04-25 19:37:59 +00:00
|
|
|
op->uses_shared_memory = 1;
|
|
|
|
op->upcall.req.readdir.refn = oi->refn;
|
|
|
|
op->upcall.req.readdir.token = od->token;
|
|
|
|
op->upcall.req.readdir.max_dirent_count =
|
2016-01-04 20:05:28 +00:00
|
|
|
ORANGEFS_MAX_DIRENT_COUNT_READDIR;
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
again:
|
|
|
|
bufi = orangefs_readdir_index_get();
|
|
|
|
if (bufi < 0) {
|
|
|
|
od->error = bufi;
|
|
|
|
return bufi;
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
op->upcall.req.readdir.buf_index = bufi;
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
r = service_operation(op, "orangefs_readdir",
|
2023-04-20 19:36:12 +00:00
|
|
|
get_interruptible_flag(inode));
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
orangefs_readdir_index_put(bufi);
|
2016-02-17 17:55:42 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
if (op_state_purged(op)) {
|
|
|
|
if (r == -EAGAIN) {
|
|
|
|
vfree(op->downcall.trailer_buf);
|
|
|
|
goto again;
|
|
|
|
} else if (r == -EIO) {
|
|
|
|
vfree(op->downcall.trailer_buf);
|
|
|
|
od->error = r;
|
|
|
|
return r;
|
|
|
|
}
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
if (r < 0) {
|
|
|
|
vfree(op->downcall.trailer_buf);
|
|
|
|
od->error = r;
|
|
|
|
return r;
|
|
|
|
} else if (op->downcall.status) {
|
|
|
|
vfree(op->downcall.trailer_buf);
|
|
|
|
od->error = op->downcall.status;
|
|
|
|
return op->downcall.status;
|
|
|
|
}
|
|
|
|
|
2017-04-25 19:38:01 +00:00
|
|
|
/*
|
|
|
|
* The maximum size is size per entry times the 512 entries plus
|
|
|
|
* the header. This is well under the limit.
|
|
|
|
*/
|
|
|
|
if (op->downcall.trailer_size > PART_SIZE) {
|
|
|
|
vfree(op->downcall.trailer_buf);
|
|
|
|
od->error = -EIO;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
resp = (struct orangefs_readdir_response_s *)
|
|
|
|
op->downcall.trailer_buf;
|
|
|
|
od->token = resp->token;
|
2017-04-25 19:38:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-04-25 19:37:59 +00:00
|
|
|
|
2017-04-25 19:38:01 +00:00
|
|
|
static int parse_readdir(struct orangefs_dir *od,
|
|
|
|
struct orangefs_kernel_op_s *op)
|
|
|
|
{
|
|
|
|
struct orangefs_dir_part *part, *new;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
part = od->part;
|
2017-05-04 17:16:04 +00:00
|
|
|
while (part) {
|
2017-04-25 19:38:01 +00:00
|
|
|
count++;
|
2017-05-04 17:16:04 +00:00
|
|
|
if (part->next)
|
|
|
|
part = part->next;
|
|
|
|
else
|
|
|
|
break;
|
2017-04-25 19:37:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:38:01 +00:00
|
|
|
new = (void *)op->downcall.trailer_buf;
|
|
|
|
new->next = NULL;
|
|
|
|
new->len = op->downcall.trailer_size -
|
|
|
|
sizeof(struct orangefs_readdir_response_s);
|
|
|
|
if (!od->part)
|
|
|
|
od->part = new;
|
|
|
|
else
|
|
|
|
part->next = new;
|
|
|
|
count++;
|
|
|
|
od->end = count << PART_SHIFT;
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-02-17 00:54:13 +00:00
|
|
|
|
2023-04-20 19:36:12 +00:00
|
|
|
static int orangefs_dir_more(struct orangefs_dir *od, struct inode *inode)
|
2017-04-25 19:38:01 +00:00
|
|
|
{
|
|
|
|
struct orangefs_kernel_op_s *op;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
op = op_alloc(ORANGEFS_VFS_OP_READDIR);
|
|
|
|
if (!op) {
|
|
|
|
od->error = -ENOMEM;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2023-04-20 19:36:12 +00:00
|
|
|
r = do_readdir(od, inode, op);
|
2017-04-25 19:38:01 +00:00
|
|
|
if (r) {
|
|
|
|
od->error = r;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
r = parse_readdir(od, op);
|
|
|
|
if (r) {
|
|
|
|
od->error = r;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
od->error = 0;
|
|
|
|
out:
|
|
|
|
op_release(op);
|
|
|
|
return od->error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fill_from_part(struct orangefs_dir_part *part,
|
2017-04-25 19:37:59 +00:00
|
|
|
struct dir_context *ctx)
|
|
|
|
{
|
2017-04-25 19:38:01 +00:00
|
|
|
const int offset = sizeof(struct orangefs_readdir_response_s);
|
2017-04-25 19:37:59 +00:00
|
|
|
struct orangefs_khandle *khandle;
|
|
|
|
__u32 *len, padlen;
|
2017-04-25 19:38:00 +00:00
|
|
|
loff_t i;
|
2017-04-25 19:37:59 +00:00
|
|
|
char *s;
|
2017-04-25 19:38:01 +00:00
|
|
|
i = ctx->pos & ~PART_MASK;
|
|
|
|
|
|
|
|
/* The file offset from userspace is too large. */
|
|
|
|
if (i > part->len)
|
2017-05-02 16:15:10 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the seek pointer is positioned just before an entry it
|
|
|
|
* should find the next entry.
|
|
|
|
*/
|
|
|
|
if (i % 8)
|
|
|
|
i = i + (8 - i%8)%8;
|
2017-04-25 19:38:01 +00:00
|
|
|
|
|
|
|
while (i < part->len) {
|
|
|
|
if (part->len < i + sizeof *len)
|
2017-05-02 16:15:10 +00:00
|
|
|
break;
|
2017-04-25 19:38:01 +00:00
|
|
|
len = (void *)part + offset + i;
|
2017-04-25 19:37:59 +00:00
|
|
|
/*
|
|
|
|
* len is the size of the string itself. padlen is the
|
|
|
|
* total size of the encoded string.
|
|
|
|
*/
|
|
|
|
padlen = (sizeof *len + *len + 1) +
|
2017-04-25 19:38:01 +00:00
|
|
|
(8 - (sizeof *len + *len + 1)%8)%8;
|
|
|
|
if (part->len < i + padlen + sizeof *khandle)
|
2017-05-02 16:15:10 +00:00
|
|
|
goto next;
|
2017-04-25 19:38:01 +00:00
|
|
|
s = (void *)part + offset + i + sizeof *len;
|
2017-04-25 19:37:59 +00:00
|
|
|
if (s[*len] != 0)
|
2017-05-02 16:15:10 +00:00
|
|
|
goto next;
|
2017-04-25 19:38:01 +00:00
|
|
|
khandle = (void *)part + offset + i + padlen;
|
2017-04-25 19:37:59 +00:00
|
|
|
if (!dir_emit(ctx, s, *len,
|
2017-04-25 19:38:01 +00:00
|
|
|
orangefs_khandle_to_ino(khandle),
|
|
|
|
DT_UNKNOWN))
|
2017-04-25 19:37:59 +00:00
|
|
|
return 0;
|
2017-04-25 19:38:00 +00:00
|
|
|
i += padlen + sizeof *khandle;
|
|
|
|
i = i + (8 - i%8)%8;
|
2017-04-25 19:38:01 +00:00
|
|
|
BUG_ON(i > part->len);
|
|
|
|
ctx->pos = (ctx->pos & PART_MASK) | i;
|
2017-05-02 16:15:10 +00:00
|
|
|
continue;
|
|
|
|
next:
|
|
|
|
i += 8;
|
2017-04-25 19:38:01 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:36:12 +00:00
|
|
|
static int orangefs_dir_fill(struct orangefs_dir *od, struct dir_context *ctx)
|
2017-04-25 19:38:01 +00:00
|
|
|
{
|
|
|
|
struct orangefs_dir_part *part;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
count = ((ctx->pos & PART_MASK) >> PART_SHIFT) - 1;
|
|
|
|
|
|
|
|
part = od->part;
|
|
|
|
while (part->next && count) {
|
|
|
|
count--;
|
|
|
|
part = part->next;
|
|
|
|
}
|
|
|
|
/* This means the userspace file offset is invalid. */
|
|
|
|
if (count) {
|
|
|
|
od->error = -EIO;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (part && part->len) {
|
|
|
|
int r;
|
|
|
|
r = fill_from_part(part, ctx);
|
|
|
|
if (r < 0) {
|
|
|
|
od->error = r;
|
|
|
|
return r;
|
|
|
|
} else if (r == 0) {
|
|
|
|
/* Userspace buffer is full. */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The part ran out of data. Move to the next
|
|
|
|
* part. */
|
|
|
|
ctx->pos = (ctx->pos & PART_MASK) +
|
|
|
|
(1 << PART_SHIFT);
|
|
|
|
part = part->next;
|
|
|
|
}
|
2017-04-25 19:37:59 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-05-02 16:15:11 +00:00
|
|
|
static loff_t orangefs_dir_llseek(struct file *file, loff_t offset,
|
|
|
|
int whence)
|
|
|
|
{
|
|
|
|
struct orangefs_dir *od = file->private_data;
|
|
|
|
/*
|
|
|
|
* Delete the stored data so userspace sees new directory
|
|
|
|
* entries.
|
|
|
|
*/
|
|
|
|
if (!whence && offset < od->end) {
|
|
|
|
struct orangefs_dir_part *part = od->part;
|
|
|
|
while (part) {
|
|
|
|
struct orangefs_dir_part *next = part->next;
|
|
|
|
vfree(part);
|
|
|
|
part = next;
|
|
|
|
}
|
|
|
|
od->token = ORANGEFS_ITERATE_START;
|
|
|
|
od->part = NULL;
|
|
|
|
od->end = 1 << PART_SHIFT;
|
|
|
|
}
|
|
|
|
return default_llseek(file, offset, whence);
|
|
|
|
}
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
static int orangefs_dir_iterate(struct file *file,
|
|
|
|
struct dir_context *ctx)
|
|
|
|
{
|
2023-04-20 19:36:12 +00:00
|
|
|
struct orangefs_dir *od = file->private_data;
|
|
|
|
struct inode *inode = file_inode(file);
|
2017-04-25 19:37:59 +00:00
|
|
|
int r;
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
if (od->error)
|
|
|
|
return od->error;
|
2015-07-17 14:38:12 +00:00
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
if (ctx->pos == 0) {
|
|
|
|
if (!dir_emit_dot(file, ctx))
|
|
|
|
return 0;
|
|
|
|
ctx->pos++;
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
2017-04-25 19:37:59 +00:00
|
|
|
if (ctx->pos == 1) {
|
|
|
|
if (!dir_emit_dotdot(file, ctx))
|
|
|
|
return 0;
|
2017-04-25 19:38:01 +00:00
|
|
|
ctx->pos = 1 << PART_SHIFT;
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:38:01 +00:00
|
|
|
/*
|
|
|
|
* The seek position is in the first synthesized part but is not
|
|
|
|
* valid.
|
|
|
|
*/
|
|
|
|
if ((ctx->pos & PART_MASK) == 0)
|
|
|
|
return -EIO;
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
r = 0;
|
|
|
|
|
2017-04-25 19:38:00 +00:00
|
|
|
/*
|
|
|
|
* Must read more if the user has sought past what has been read
|
|
|
|
* so far. Stop a user who has sought past the end.
|
|
|
|
*/
|
2017-04-25 19:38:02 +00:00
|
|
|
while (od->token != ORANGEFS_ITERATE_END &&
|
2017-04-25 19:38:01 +00:00
|
|
|
ctx->pos > od->end) {
|
2023-04-20 19:36:12 +00:00
|
|
|
r = orangefs_dir_more(od, inode);
|
2017-04-25 19:38:00 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
2017-04-25 19:38:02 +00:00
|
|
|
if (od->token == ORANGEFS_ITERATE_END && ctx->pos > od->end)
|
2017-04-25 19:38:00 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* Then try to fill if there's any left in the buffer. */
|
2017-04-25 19:38:01 +00:00
|
|
|
if (ctx->pos < od->end) {
|
2023-04-20 19:36:12 +00:00
|
|
|
r = orangefs_dir_fill(od, ctx);
|
2017-04-25 19:37:59 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:38:00 +00:00
|
|
|
/* Finally get some more and try to fill. */
|
2017-04-25 19:38:02 +00:00
|
|
|
if (od->token != ORANGEFS_ITERATE_END) {
|
2023-04-20 19:36:12 +00:00
|
|
|
r = orangefs_dir_more(od, inode);
|
2017-04-25 19:37:59 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
2023-04-20 19:36:12 +00:00
|
|
|
r = orangefs_dir_fill(od, ctx);
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 19:37:59 +00:00
|
|
|
return r;
|
2015-07-17 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
static int orangefs_dir_open(struct inode *inode, struct file *file)
|
2015-07-17 14:38:12 +00:00
|
|
|
{
|
2017-04-25 19:37:59 +00:00
|
|
|
struct orangefs_dir *od;
|
|
|
|
file->private_data = kmalloc(sizeof(struct orangefs_dir),
|
|
|
|
GFP_KERNEL);
|
2015-07-17 14:38:12 +00:00
|
|
|
if (!file->private_data)
|
|
|
|
return -ENOMEM;
|
2017-04-25 19:37:59 +00:00
|
|
|
od = file->private_data;
|
2017-04-25 19:38:02 +00:00
|
|
|
od->token = ORANGEFS_ITERATE_START;
|
2017-04-25 19:38:01 +00:00
|
|
|
od->part = NULL;
|
|
|
|
od->end = 1 << PART_SHIFT;
|
2017-04-25 19:37:59 +00:00
|
|
|
od->error = 0;
|
2015-07-17 14:38:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
static int orangefs_dir_release(struct inode *inode, struct file *file)
|
2015-07-17 14:38:12 +00:00
|
|
|
{
|
2017-04-25 19:37:59 +00:00
|
|
|
struct orangefs_dir *od = file->private_data;
|
2017-04-25 19:38:01 +00:00
|
|
|
struct orangefs_dir_part *part = od->part;
|
|
|
|
while (part) {
|
|
|
|
struct orangefs_dir_part *next = part->next;
|
|
|
|
vfree(part);
|
|
|
|
part = next;
|
|
|
|
}
|
2017-04-25 19:37:59 +00:00
|
|
|
kfree(od);
|
2015-07-17 14:38:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:12:14 +00:00
|
|
|
const struct file_operations orangefs_dir_operations = {
|
2017-05-02 16:15:11 +00:00
|
|
|
.llseek = orangefs_dir_llseek,
|
2015-07-17 14:38:12 +00:00
|
|
|
.read = generic_read_dir,
|
2022-10-03 17:05:38 +00:00
|
|
|
.iterate_shared = orangefs_dir_iterate,
|
2015-11-24 20:12:14 +00:00
|
|
|
.open = orangefs_dir_open,
|
2017-04-25 19:37:59 +00:00
|
|
|
.release = orangefs_dir_release
|
2015-07-17 14:38:12 +00:00
|
|
|
};
|