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
|
2015-07-17 22:38:12 +08:00
|
|
|
/*
|
|
|
|
* (C) 2001 Clemson University and The University of Chicago
|
2018-02-14 04:13:46 +08:00
|
|
|
* Copyright 2018 Omnibond Systems, L.L.C.
|
2015-07-17 22:38:12 +08:00
|
|
|
*
|
|
|
|
* See COPYING in top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Linux VFS inode operations.
|
|
|
|
*/
|
|
|
|
|
2016-11-01 21:40:13 +08:00
|
|
|
#include <linux/bvec.h>
|
2015-07-17 22:38:12 +08:00
|
|
|
#include "protocol.h"
|
2015-12-05 01:56:14 +08:00
|
|
|
#include "orangefs-kernel.h"
|
|
|
|
#include "orangefs-bufmap.h"
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
static int orangefs_writepage_locked(struct page *page,
|
|
|
|
struct writeback_control *wbc)
|
2018-02-23 02:10:43 +08:00
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
2018-12-15 04:24:43 +08:00
|
|
|
struct orangefs_write_range *wr = NULL;
|
2018-02-23 02:10:43 +08:00
|
|
|
struct iov_iter iter;
|
|
|
|
struct bio_vec bv;
|
|
|
|
size_t len, wlen;
|
|
|
|
ssize_t ret;
|
|
|
|
loff_t off;
|
|
|
|
|
|
|
|
set_page_writeback(page);
|
|
|
|
|
|
|
|
len = i_size_read(inode);
|
2018-12-15 04:24:43 +08:00
|
|
|
if (PagePrivate(page)) {
|
|
|
|
wr = (struct orangefs_write_range *)page_private(page);
|
2019-02-13 04:19:06 +08:00
|
|
|
WARN_ON(wr->pos >= len);
|
2018-12-15 04:24:43 +08:00
|
|
|
off = wr->pos;
|
|
|
|
if (off + wr->len > len)
|
|
|
|
wlen = len - off;
|
|
|
|
else
|
|
|
|
wlen = wr->len;
|
|
|
|
} else {
|
|
|
|
WARN_ON(1);
|
|
|
|
off = page_offset(page);
|
|
|
|
if (off + PAGE_SIZE > len)
|
|
|
|
wlen = len - off;
|
|
|
|
else
|
|
|
|
wlen = PAGE_SIZE;
|
2018-02-23 02:10:43 +08:00
|
|
|
}
|
2018-12-15 04:24:43 +08:00
|
|
|
/* Should've been handled in orangefs_invalidatepage. */
|
|
|
|
WARN_ON(off == len || off + wlen > len);
|
2018-02-23 02:10:43 +08:00
|
|
|
|
|
|
|
bv.bv_page = page;
|
|
|
|
bv.bv_len = wlen;
|
|
|
|
bv.bv_offset = off % PAGE_SIZE;
|
2018-12-15 04:24:43 +08:00
|
|
|
WARN_ON(wlen == 0);
|
2018-02-23 02:10:43 +08:00
|
|
|
iov_iter_bvec(&iter, WRITE, &bv, 1, wlen);
|
|
|
|
|
|
|
|
ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, wlen,
|
2019-11-27 01:39:37 +08:00
|
|
|
len, wr, NULL, NULL);
|
2018-02-23 02:10:43 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
SetPageError(page);
|
|
|
|
mapping_set_error(page->mapping, ret);
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-06-02 12:48:00 +08:00
|
|
|
kfree(detach_page_private(page));
|
2018-12-15 04:24:43 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int orangefs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = orangefs_writepage_locked(page, wbc);
|
2018-02-23 02:10:43 +08:00
|
|
|
unlock_page(page);
|
|
|
|
end_page_writeback(page);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-13 04:19:06 +08:00
|
|
|
struct orangefs_writepages {
|
|
|
|
loff_t off;
|
|
|
|
size_t len;
|
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
|
|
|
int maxpages;
|
|
|
|
int npages;
|
|
|
|
struct page **pages;
|
|
|
|
struct bio_vec *bv;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int orangefs_writepages_work(struct orangefs_writepages *ow,
|
|
|
|
struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
struct inode *inode = ow->pages[0]->mapping->host;
|
|
|
|
struct orangefs_write_range *wrp, wr;
|
|
|
|
struct iov_iter iter;
|
|
|
|
ssize_t ret;
|
|
|
|
size_t len;
|
|
|
|
loff_t off;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
len = i_size_read(inode);
|
|
|
|
|
|
|
|
for (i = 0; i < ow->npages; i++) {
|
|
|
|
set_page_writeback(ow->pages[i]);
|
|
|
|
ow->bv[i].bv_page = ow->pages[i];
|
|
|
|
ow->bv[i].bv_len = min(page_offset(ow->pages[i]) + PAGE_SIZE,
|
|
|
|
ow->off + ow->len) -
|
|
|
|
max(ow->off, page_offset(ow->pages[i]));
|
|
|
|
if (i == 0)
|
|
|
|
ow->bv[i].bv_offset = ow->off -
|
|
|
|
page_offset(ow->pages[i]);
|
|
|
|
else
|
|
|
|
ow->bv[i].bv_offset = 0;
|
|
|
|
}
|
|
|
|
iov_iter_bvec(&iter, WRITE, ow->bv, ow->npages, ow->len);
|
|
|
|
|
|
|
|
WARN_ON(ow->off >= len);
|
|
|
|
if (ow->off + ow->len > len)
|
|
|
|
ow->len = len - ow->off;
|
|
|
|
|
|
|
|
off = ow->off;
|
|
|
|
wr.uid = ow->uid;
|
|
|
|
wr.gid = ow->gid;
|
|
|
|
ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len,
|
2019-11-27 01:39:37 +08:00
|
|
|
0, &wr, NULL, NULL);
|
2019-02-13 04:19:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
for (i = 0; i < ow->npages; i++) {
|
|
|
|
SetPageError(ow->pages[i]);
|
|
|
|
mapping_set_error(ow->pages[i]->mapping, ret);
|
|
|
|
if (PagePrivate(ow->pages[i])) {
|
|
|
|
wrp = (struct orangefs_write_range *)
|
|
|
|
page_private(ow->pages[i]);
|
|
|
|
ClearPagePrivate(ow->pages[i]);
|
|
|
|
put_page(ow->pages[i]);
|
|
|
|
kfree(wrp);
|
|
|
|
}
|
|
|
|
end_page_writeback(ow->pages[i]);
|
|
|
|
unlock_page(ow->pages[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
for (i = 0; i < ow->npages; i++) {
|
|
|
|
if (PagePrivate(ow->pages[i])) {
|
|
|
|
wrp = (struct orangefs_write_range *)
|
|
|
|
page_private(ow->pages[i]);
|
|
|
|
ClearPagePrivate(ow->pages[i]);
|
|
|
|
put_page(ow->pages[i]);
|
|
|
|
kfree(wrp);
|
|
|
|
}
|
|
|
|
end_page_writeback(ow->pages[i]);
|
|
|
|
unlock_page(ow->pages[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int orangefs_writepages_callback(struct page *page,
|
|
|
|
struct writeback_control *wbc, void *data)
|
|
|
|
{
|
|
|
|
struct orangefs_writepages *ow = data;
|
|
|
|
struct orangefs_write_range *wr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!PagePrivate(page)) {
|
|
|
|
unlock_page(page);
|
|
|
|
/* It's not private so there's nothing to write, right? */
|
|
|
|
printk("writepages_callback not private!\n");
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
wr = (struct orangefs_write_range *)page_private(page);
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
if (ow->npages == 0) {
|
|
|
|
ow->off = wr->pos;
|
|
|
|
ow->len = wr->len;
|
|
|
|
ow->uid = wr->uid;
|
|
|
|
ow->gid = wr->gid;
|
|
|
|
ow->pages[ow->npages++] = page;
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) {
|
|
|
|
orangefs_writepages_work(ow, wbc);
|
|
|
|
ow->npages = 0;
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (ow->off + ow->len == wr->pos) {
|
|
|
|
ow->len += wr->len;
|
|
|
|
ow->pages[ow->npages++] = page;
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
if (ret == -1) {
|
|
|
|
if (ow->npages) {
|
|
|
|
orangefs_writepages_work(ow, wbc);
|
|
|
|
ow->npages = 0;
|
|
|
|
}
|
|
|
|
ret = orangefs_writepage_locked(page, wbc);
|
|
|
|
mapping_set_error(page->mapping, ret);
|
|
|
|
unlock_page(page);
|
|
|
|
end_page_writeback(page);
|
|
|
|
} else {
|
|
|
|
if (ow->npages == ow->maxpages) {
|
|
|
|
orangefs_writepages_work(ow, wbc);
|
|
|
|
ow->npages = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int orangefs_writepages(struct address_space *mapping,
|
|
|
|
struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
struct orangefs_writepages *ow;
|
|
|
|
struct blk_plug plug;
|
|
|
|
int ret;
|
|
|
|
ow = kzalloc(sizeof(struct orangefs_writepages), GFP_KERNEL);
|
|
|
|
if (!ow)
|
|
|
|
return -ENOMEM;
|
|
|
|
ow->maxpages = orangefs_bufmap_size_query()/PAGE_SIZE;
|
|
|
|
ow->pages = kcalloc(ow->maxpages, sizeof(struct page *), GFP_KERNEL);
|
|
|
|
if (!ow->pages) {
|
|
|
|
kfree(ow);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
ow->bv = kcalloc(ow->maxpages, sizeof(struct bio_vec), GFP_KERNEL);
|
|
|
|
if (!ow->bv) {
|
|
|
|
kfree(ow->pages);
|
|
|
|
kfree(ow);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
blk_start_plug(&plug);
|
|
|
|
ret = write_cache_pages(mapping, wbc, orangefs_writepages_callback, ow);
|
|
|
|
if (ow->npages)
|
|
|
|
ret = orangefs_writepages_work(ow, wbc);
|
|
|
|
blk_finish_plug(&plug);
|
|
|
|
kfree(ow->pages);
|
|
|
|
kfree(ow->bv);
|
|
|
|
kfree(ow);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:59:29 +08:00
|
|
|
static int orangefs_launder_page(struct page *);
|
|
|
|
|
2018-02-16 02:02:43 +08:00
|
|
|
static int orangefs_readpage(struct file *file, struct page *page)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
2018-02-17 04:51:24 +08:00
|
|
|
struct iov_iter iter;
|
|
|
|
struct bio_vec bv;
|
|
|
|
ssize_t ret;
|
2019-03-26 06:59:29 +08:00
|
|
|
loff_t off; /* offset into this page */
|
|
|
|
pgoff_t index; /* which page */
|
|
|
|
struct page *next_page;
|
|
|
|
char *kaddr;
|
|
|
|
loff_t read_size;
|
|
|
|
int buffer_index = -1; /* orangefs shared memory slot */
|
|
|
|
int slot_index; /* index into slot */
|
|
|
|
int remaining;
|
|
|
|
|
|
|
|
/*
|
2020-04-08 20:52:40 +08:00
|
|
|
* Get up to this many bytes from Orangefs at a time and try
|
|
|
|
* to fill them into the page cache at once. Tests with dd made
|
|
|
|
* this seem like a reasonable static number, if there was
|
|
|
|
* interest perhaps this number could be made setable through
|
|
|
|
* sysfs...
|
2019-03-26 06:59:29 +08:00
|
|
|
*/
|
2020-04-08 20:52:40 +08:00
|
|
|
read_size = 524288;
|
2019-03-26 06:59:29 +08:00
|
|
|
|
|
|
|
if (PageDirty(page))
|
|
|
|
orangefs_launder_page(page);
|
2018-02-17 04:51:24 +08:00
|
|
|
|
|
|
|
off = page_offset(page);
|
2019-03-26 06:59:29 +08:00
|
|
|
index = off >> PAGE_SHIFT;
|
2018-02-17 04:51:24 +08:00
|
|
|
bv.bv_page = page;
|
|
|
|
bv.bv_len = PAGE_SIZE;
|
|
|
|
bv.bv_offset = 0;
|
|
|
|
iov_iter_bvec(&iter, READ, &bv, 1, PAGE_SIZE);
|
|
|
|
|
|
|
|
ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter,
|
2019-11-27 01:39:37 +08:00
|
|
|
read_size, inode->i_size, NULL, &buffer_index, file);
|
2019-03-26 06:59:29 +08:00
|
|
|
remaining = ret;
|
2015-10-09 06:31:05 +08:00
|
|
|
/* this will only zero remaining unread portions of the page data */
|
2018-02-17 04:51:24 +08:00
|
|
|
iov_iter_zero(~0U, &iter);
|
2015-07-17 22:38:12 +08:00
|
|
|
/* takes care of potential aliasing */
|
|
|
|
flush_dcache_page(page);
|
2018-02-17 04:51:24 +08:00
|
|
|
if (ret < 0) {
|
2015-07-17 22:38:12 +08:00
|
|
|
SetPageError(page);
|
2019-03-26 06:59:29 +08:00
|
|
|
unlock_page(page);
|
|
|
|
goto out;
|
2015-07-17 22:38:12 +08:00
|
|
|
} else {
|
|
|
|
SetPageUptodate(page);
|
|
|
|
if (PageError(page))
|
|
|
|
ClearPageError(page);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
/* unlock the page after the ->readpage() routine completes */
|
|
|
|
unlock_page(page);
|
2019-03-26 06:59:29 +08:00
|
|
|
|
|
|
|
if (remaining > PAGE_SIZE) {
|
|
|
|
slot_index = 0;
|
|
|
|
while ((remaining - PAGE_SIZE) >= PAGE_SIZE) {
|
|
|
|
remaining -= PAGE_SIZE;
|
|
|
|
/*
|
|
|
|
* It is an optimization to try and fill more than one
|
|
|
|
* page... by now we've already gotten the single
|
|
|
|
* page we were after, if stuff doesn't seem to
|
|
|
|
* be going our way at this point just return
|
|
|
|
* and hope for the best.
|
|
|
|
*
|
|
|
|
* If we look for pages and they're already there is
|
|
|
|
* one reason to give up, and if they're not there
|
|
|
|
* and we can't create them is another reason.
|
|
|
|
*/
|
|
|
|
|
|
|
|
index++;
|
|
|
|
slot_index++;
|
|
|
|
next_page = find_get_page(inode->i_mapping, index);
|
|
|
|
if (next_page) {
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s: found next page, quitting\n",
|
|
|
|
__func__);
|
|
|
|
put_page(next_page);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
next_page = find_or_create_page(inode->i_mapping,
|
|
|
|
index,
|
|
|
|
GFP_KERNEL);
|
|
|
|
/*
|
|
|
|
* I've never hit this, leave it as a printk for
|
|
|
|
* now so it will be obvious.
|
|
|
|
*/
|
|
|
|
if (!next_page) {
|
|
|
|
printk("%s: can't create next page, quitting\n",
|
|
|
|
__func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
kaddr = kmap_atomic(next_page);
|
|
|
|
orangefs_bufmap_page_fill(kaddr,
|
|
|
|
buffer_index,
|
|
|
|
slot_index);
|
|
|
|
kunmap_atomic(kaddr);
|
|
|
|
SetPageUptodate(next_page);
|
|
|
|
unlock_page(next_page);
|
|
|
|
put_page(next_page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (buffer_index != -1)
|
|
|
|
orangefs_bufmap_put(buffer_index);
|
2015-07-17 22:38:12 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
static int orangefs_write_begin(struct file *file,
|
|
|
|
struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned flags, struct page **pagep,
|
|
|
|
void **fsdata)
|
|
|
|
{
|
|
|
|
struct orangefs_write_range *wr;
|
|
|
|
struct page *page;
|
|
|
|
pgoff_t index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
index = pos >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
page = grab_cache_page_write_begin(mapping, index, flags);
|
|
|
|
if (!page)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
*pagep = page;
|
|
|
|
|
|
|
|
if (PageDirty(page) && !PagePrivate(page)) {
|
|
|
|
/*
|
|
|
|
* Should be impossible. If it happens, launder the page
|
|
|
|
* since we don't know what's dirty. This will WARN in
|
|
|
|
* orangefs_writepage_locked.
|
|
|
|
*/
|
|
|
|
ret = orangefs_launder_page(page);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (PagePrivate(page)) {
|
|
|
|
struct orangefs_write_range *wr;
|
|
|
|
wr = (struct orangefs_write_range *)page_private(page);
|
|
|
|
if (wr->pos + wr->len == pos &&
|
|
|
|
uid_eq(wr->uid, current_fsuid()) &&
|
|
|
|
gid_eq(wr->gid, current_fsgid())) {
|
|
|
|
wr->len += len;
|
|
|
|
goto okay;
|
|
|
|
} else {
|
|
|
|
ret = orangefs_launder_page(page);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wr = kmalloc(sizeof *wr, GFP_KERNEL);
|
|
|
|
if (!wr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
wr->pos = pos;
|
|
|
|
wr->len = len;
|
|
|
|
wr->uid = current_fsuid();
|
|
|
|
wr->gid = current_fsgid();
|
2020-06-02 12:48:00 +08:00
|
|
|
attach_page_private(page, wr);
|
2018-12-15 04:24:43 +08:00
|
|
|
okay:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-23 02:10:43 +08:00
|
|
|
static int orangefs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata)
|
|
|
|
{
|
2019-02-13 04:19:06 +08:00
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
loff_t last_pos = pos + copied;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No need to use i_size_read() here, the i_size
|
|
|
|
* cannot change under us because we hold the i_mutex.
|
|
|
|
*/
|
|
|
|
if (last_pos > inode->i_size)
|
|
|
|
i_size_write(inode, last_pos);
|
|
|
|
|
|
|
|
/* zero the stale part of the page if we did a short copy */
|
|
|
|
if (!PageUptodate(page)) {
|
|
|
|
unsigned from = pos & (PAGE_SIZE - 1);
|
|
|
|
if (copied < len) {
|
|
|
|
zero_user(page, from + copied, len - copied);
|
|
|
|
}
|
|
|
|
/* Set fully written pages uptodate. */
|
|
|
|
if (pos == page_offset(page) &&
|
|
|
|
(len == PAGE_SIZE || pos + len == inode->i_size)) {
|
|
|
|
zero_user_segment(page, from + copied, PAGE_SIZE);
|
|
|
|
SetPageUptodate(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_page_dirty(page);
|
|
|
|
unlock_page(page);
|
|
|
|
put_page(page);
|
|
|
|
|
2018-02-23 02:10:43 +08:00
|
|
|
mark_inode_dirty_sync(file_inode(file));
|
2019-02-13 04:19:06 +08:00
|
|
|
return copied;
|
2018-02-23 02:10:43 +08:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
static void orangefs_invalidatepage(struct page *page,
|
2015-07-17 22:38:12 +08:00
|
|
|
unsigned int offset,
|
|
|
|
unsigned int length)
|
|
|
|
{
|
2018-12-15 04:24:43 +08:00
|
|
|
struct orangefs_write_range *wr;
|
|
|
|
wr = (struct orangefs_write_range *)page_private(page);
|
|
|
|
|
|
|
|
if (offset == 0 && length == PAGE_SIZE) {
|
2020-06-02 12:48:00 +08:00
|
|
|
kfree(detach_page_private(page));
|
2019-02-13 04:19:06 +08:00
|
|
|
return;
|
2018-12-15 04:24:43 +08:00
|
|
|
/* write range entirely within invalidate range (or equal) */
|
|
|
|
} else if (page_offset(page) + offset <= wr->pos &&
|
|
|
|
wr->pos + wr->len <= page_offset(page) + offset + length) {
|
2020-06-02 12:48:00 +08:00
|
|
|
kfree(detach_page_private(page));
|
2018-12-15 04:24:43 +08:00
|
|
|
/* XXX is this right? only caller in fs */
|
|
|
|
cancel_dirty_page(page);
|
2019-02-13 04:19:06 +08:00
|
|
|
return;
|
2018-12-15 04:24:43 +08:00
|
|
|
/* invalidate range chops off end of write range */
|
|
|
|
} else if (wr->pos < page_offset(page) + offset &&
|
|
|
|
wr->pos + wr->len <= page_offset(page) + offset + length &&
|
|
|
|
page_offset(page) + offset < wr->pos + wr->len) {
|
|
|
|
size_t x;
|
|
|
|
x = wr->pos + wr->len - (page_offset(page) + offset);
|
|
|
|
WARN_ON(x > wr->len);
|
|
|
|
wr->len -= x;
|
|
|
|
wr->uid = current_fsuid();
|
|
|
|
wr->gid = current_fsgid();
|
|
|
|
/* invalidate range chops off beginning of write range */
|
|
|
|
} else if (page_offset(page) + offset <= wr->pos &&
|
|
|
|
page_offset(page) + offset + length < wr->pos + wr->len &&
|
|
|
|
wr->pos < page_offset(page) + offset + length) {
|
|
|
|
size_t x;
|
|
|
|
x = page_offset(page) + offset + length - wr->pos;
|
|
|
|
WARN_ON(x > wr->len);
|
|
|
|
wr->pos += x;
|
|
|
|
wr->len -= x;
|
|
|
|
wr->uid = current_fsuid();
|
|
|
|
wr->gid = current_fsgid();
|
|
|
|
/* invalidate range entirely within write range (punch hole) */
|
|
|
|
} else if (wr->pos < page_offset(page) + offset &&
|
|
|
|
page_offset(page) + offset + length < wr->pos + wr->len) {
|
|
|
|
/* XXX what do we do here... should not WARN_ON */
|
|
|
|
WARN_ON(1);
|
|
|
|
/* punch hole */
|
|
|
|
/*
|
|
|
|
* should we just ignore this and write it out anyway?
|
|
|
|
* it hardly makes sense
|
|
|
|
*/
|
2019-02-13 04:19:06 +08:00
|
|
|
return;
|
2018-12-15 04:24:43 +08:00
|
|
|
/* non-overlapping ranges */
|
|
|
|
} else {
|
|
|
|
/* WARN if they do overlap */
|
|
|
|
if (!((page_offset(page) + offset + length <= wr->pos) ^
|
|
|
|
(wr->pos + wr->len <= page_offset(page) + offset))) {
|
|
|
|
WARN_ON(1);
|
|
|
|
printk("invalidate range offset %llu length %u\n",
|
|
|
|
page_offset(page) + offset, length);
|
|
|
|
printk("write range offset %llu length %zu\n",
|
|
|
|
wr->pos, wr->len);
|
|
|
|
}
|
2019-02-13 04:19:06 +08:00
|
|
|
return;
|
2018-12-15 04:24:43 +08:00
|
|
|
}
|
2019-02-13 04:19:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Above there are returns where wr is freed or where we WARN.
|
|
|
|
* Thus the following runs if wr was modified above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
orangefs_launder_page(page);
|
2018-12-15 04:24:43 +08:00
|
|
|
}
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
static int orangefs_releasepage(struct page *page, gfp_t foo)
|
|
|
|
{
|
|
|
|
return !PagePrivate(page);
|
|
|
|
}
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
static void orangefs_freepage(struct page *page)
|
|
|
|
{
|
2020-06-02 12:48:00 +08:00
|
|
|
kfree(detach_page_private(page));
|
2015-07-17 22:38:12 +08:00
|
|
|
}
|
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
static int orangefs_launder_page(struct page *page)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2018-12-15 04:24:43 +08:00
|
|
|
int r = 0;
|
|
|
|
struct writeback_control wbc = {
|
|
|
|
.sync_mode = WB_SYNC_ALL,
|
|
|
|
.nr_to_write = 0,
|
|
|
|
};
|
|
|
|
wait_on_page_writeback(page);
|
|
|
|
if (clear_page_dirty_for_io(page)) {
|
|
|
|
r = orangefs_writepage_locked(page, &wbc);
|
|
|
|
end_page_writeback(page);
|
|
|
|
}
|
|
|
|
return r;
|
2015-07-17 22:38:12 +08:00
|
|
|
}
|
|
|
|
|
2016-06-10 03:38:03 +08:00
|
|
|
static ssize_t orangefs_direct_IO(struct kiocb *iocb,
|
|
|
|
struct iov_iter *iter)
|
|
|
|
{
|
2018-11-07 03:54:49 +08:00
|
|
|
/*
|
|
|
|
* Comment from original do_readv_writev:
|
|
|
|
* Common entry point for read/write/readv/writev
|
|
|
|
* This function will dispatch it to either the direct I/O
|
|
|
|
* or buffered I/O path depending on the mount options and/or
|
|
|
|
* augmented/extended metadata attached to the file.
|
|
|
|
* Note: File extended attributes override any mount options.
|
|
|
|
*/
|
2018-02-17 04:51:24 +08:00
|
|
|
struct file *file = iocb->ki_filp;
|
2018-11-07 03:54:49 +08:00
|
|
|
loff_t pos = iocb->ki_pos;
|
|
|
|
enum ORANGEFS_io_type type = iov_iter_rw(iter) == WRITE ?
|
|
|
|
ORANGEFS_IO_WRITE : ORANGEFS_IO_READ;
|
|
|
|
loff_t *offset = &pos;
|
|
|
|
struct inode *inode = file->f_mapping->host;
|
|
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
|
|
struct orangefs_khandle *handle = &orangefs_inode->refn.khandle;
|
|
|
|
size_t count = iov_iter_count(iter);
|
|
|
|
ssize_t total_count = 0;
|
|
|
|
ssize_t ret = -EINVAL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)count);
|
|
|
|
|
|
|
|
if (type == ORANGEFS_IO_WRITE) {
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): proceeding with offset : %llu, "
|
|
|
|
"size %d\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
llu(*offset),
|
|
|
|
(int)count);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (iov_iter_count(iter)) {
|
|
|
|
size_t each_count = iov_iter_count(iter);
|
|
|
|
size_t amt_complete;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* how much to transfer in this loop iteration */
|
|
|
|
if (each_count > orangefs_bufmap_size_query())
|
|
|
|
each_count = orangefs_bufmap_size_query();
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): size of each_count(%d)\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)each_count);
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): BEFORE wait_for_io: offset is %d\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)*offset);
|
|
|
|
|
|
|
|
ret = wait_for_direct_io(type, inode, offset, iter,
|
2019-11-27 01:39:37 +08:00
|
|
|
each_count, 0, NULL, NULL, file);
|
2018-11-07 03:54:49 +08:00
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): return from wait_for_io:%d\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)ret);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
*offset += ret;
|
|
|
|
total_count += ret;
|
|
|
|
amt_complete = ret;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): AFTER wait_for_io: offset is %d\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)*offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we got a short I/O operations,
|
|
|
|
* fall out and return what we got so far
|
|
|
|
*/
|
|
|
|
if (amt_complete < each_count)
|
|
|
|
break;
|
|
|
|
} /*end while */
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (total_count > 0)
|
|
|
|
ret = total_count;
|
|
|
|
if (ret > 0) {
|
|
|
|
if (type == ORANGEFS_IO_READ) {
|
|
|
|
file_accessed(file);
|
|
|
|
} else {
|
|
|
|
file_update_time(file);
|
|
|
|
if (*offset > i_size_read(inode))
|
|
|
|
i_size_write(inode, *offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_FILE_DEBUG,
|
|
|
|
"%s(%pU): Value(%d) returned.\n",
|
|
|
|
__func__,
|
|
|
|
handle,
|
|
|
|
(int)ret);
|
|
|
|
|
|
|
|
return ret;
|
2016-06-10 03:38:03 +08:00
|
|
|
}
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
/** ORANGEFS2 implementation of address space operations */
|
2018-04-04 00:27:13 +08:00
|
|
|
static const struct address_space_operations orangefs_address_operations = {
|
2018-02-23 02:10:43 +08:00
|
|
|
.writepage = orangefs_writepage,
|
2015-11-25 04:12:14 +08:00
|
|
|
.readpage = orangefs_readpage,
|
2019-02-13 04:19:06 +08:00
|
|
|
.writepages = orangefs_writepages,
|
2018-02-23 02:10:43 +08:00
|
|
|
.set_page_dirty = __set_page_dirty_nobuffers,
|
2018-12-15 04:24:43 +08:00
|
|
|
.write_begin = orangefs_write_begin,
|
2018-02-23 02:10:43 +08:00
|
|
|
.write_end = orangefs_write_end,
|
2015-11-25 04:12:14 +08:00
|
|
|
.invalidatepage = orangefs_invalidatepage,
|
|
|
|
.releasepage = orangefs_releasepage,
|
2018-12-15 04:24:43 +08:00
|
|
|
.freepage = orangefs_freepage,
|
|
|
|
.launder_page = orangefs_launder_page,
|
2016-06-10 03:38:03 +08:00
|
|
|
.direct_IO = orangefs_direct_IO,
|
2015-07-17 22:38:12 +08:00
|
|
|
};
|
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
vm_fault_t orangefs_page_mkwrite(struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
struct page *page = vmf->page;
|
|
|
|
struct inode *inode = file_inode(vmf->vma->vm_file);
|
2019-02-13 04:19:06 +08:00
|
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
|
|
unsigned long *bitlock = &orangefs_inode->bitlock;
|
|
|
|
vm_fault_t ret;
|
2018-12-15 04:24:43 +08:00
|
|
|
struct orangefs_write_range *wr;
|
|
|
|
|
2019-02-13 04:19:06 +08:00
|
|
|
sb_start_pagefault(inode->i_sb);
|
|
|
|
|
|
|
|
if (wait_on_bit(bitlock, 1, TASK_KILLABLE)) {
|
|
|
|
ret = VM_FAULT_RETRY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-12-15 04:24:43 +08:00
|
|
|
lock_page(page);
|
|
|
|
if (PageDirty(page) && !PagePrivate(page)) {
|
|
|
|
/*
|
|
|
|
* Should be impossible. If it happens, launder the page
|
|
|
|
* since we don't know what's dirty. This will WARN in
|
|
|
|
* orangefs_writepage_locked.
|
|
|
|
*/
|
|
|
|
if (orangefs_launder_page(page)) {
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
2018-12-15 04:24:43 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PagePrivate(page)) {
|
|
|
|
wr = (struct orangefs_write_range *)page_private(page);
|
|
|
|
if (uid_eq(wr->uid, current_fsuid()) &&
|
|
|
|
gid_eq(wr->gid, current_fsgid())) {
|
|
|
|
wr->pos = page_offset(page);
|
|
|
|
wr->len = PAGE_SIZE;
|
|
|
|
goto okay;
|
|
|
|
} else {
|
|
|
|
if (orangefs_launder_page(page)) {
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
2018-12-15 04:24:43 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wr = kmalloc(sizeof *wr, GFP_KERNEL);
|
|
|
|
if (!wr) {
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY;
|
2018-12-15 04:24:43 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wr->pos = page_offset(page);
|
|
|
|
wr->len = PAGE_SIZE;
|
|
|
|
wr->uid = current_fsuid();
|
|
|
|
wr->gid = current_fsgid();
|
2020-06-02 12:48:00 +08:00
|
|
|
attach_page_private(page, wr);
|
2018-12-15 04:24:43 +08:00
|
|
|
okay:
|
|
|
|
|
|
|
|
file_update_time(vmf->vma->vm_file);
|
|
|
|
if (page->mapping != inode->i_mapping) {
|
|
|
|
unlock_page(page);
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = VM_FAULT_LOCKED|VM_FAULT_NOPAGE;
|
2018-12-15 04:24:43 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We mark the page dirty already here so that when freeze is in
|
|
|
|
* progress, we are guaranteed that writeback during freezing will
|
|
|
|
* see the dirty page and writeprotect it again.
|
|
|
|
*/
|
|
|
|
set_page_dirty(page);
|
|
|
|
wait_for_stable_page(page);
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = VM_FAULT_LOCKED;
|
2018-12-15 04:24:43 +08:00
|
|
|
out:
|
|
|
|
sb_end_pagefault(inode->i_sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2015-11-25 04:12:14 +08:00
|
|
|
struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
|
|
|
|
struct orangefs_kernel_op_s *new_op;
|
2016-03-24 05:06:25 +08:00
|
|
|
loff_t orig_size;
|
2015-07-17 22:38:12 +08:00
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
|
|
|
"%s: %pU: Handle is %pU | fs_id %d | size is %llu\n",
|
|
|
|
__func__,
|
|
|
|
get_khandle_from_ino(inode),
|
2015-11-25 04:12:14 +08:00
|
|
|
&orangefs_inode->refn.khandle,
|
|
|
|
orangefs_inode->refn.fs_id,
|
2015-07-17 22:38:12 +08:00
|
|
|
iattr->ia_size);
|
|
|
|
|
2016-03-24 05:06:25 +08:00
|
|
|
/* Ensure that we have a up to date size, so we know if it changed. */
|
2018-02-08 02:44:50 +08:00
|
|
|
ret = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_SIZE);
|
2016-03-24 05:06:25 +08:00
|
|
|
if (ret == -ESTALE)
|
|
|
|
ret = -EIO;
|
|
|
|
if (ret) {
|
|
|
|
gossip_err("%s: orangefs_inode_getattr failed, ret:%d:.\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
orig_size = i_size_read(inode);
|
|
|
|
|
2019-04-30 01:09:48 +08:00
|
|
|
/* This is truncate_setsize in a different order. */
|
|
|
|
truncate_pagecache(inode, iattr->ia_size);
|
|
|
|
i_size_write(inode, iattr->ia_size);
|
|
|
|
if (iattr->ia_size > orig_size)
|
|
|
|
pagecache_isize_extended(inode, orig_size, iattr->ia_size);
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
new_op = op_alloc(ORANGEFS_VFS_OP_TRUNCATE);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (!new_op)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
new_op->upcall.req.truncate.refn = orangefs_inode->refn;
|
2015-07-17 22:38:12 +08:00
|
|
|
new_op->upcall.req.truncate.size = (__s64) iattr->ia_size;
|
|
|
|
|
2018-05-12 05:11:48 +08:00
|
|
|
ret = service_operation(new_op,
|
|
|
|
__func__,
|
|
|
|
get_interruptible_flag(inode));
|
2015-07-17 22:38:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the truncate has no downcall members to retrieve, but
|
|
|
|
* the status value tells us if it went through ok or not
|
|
|
|
*/
|
2018-05-12 05:11:48 +08:00
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG, "%s: ret:%d:\n", __func__, ret);
|
2015-07-17 22:38:12 +08:00
|
|
|
|
|
|
|
op_release(new_op);
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
2016-04-05 04:26:36 +08:00
|
|
|
if (orig_size != i_size_read(inode))
|
2015-07-17 22:38:12 +08:00
|
|
|
iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-14 04:13:46 +08:00
|
|
|
int __orangefs_setattr(struct inode *inode, struct iattr *iattr)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2018-02-13 04:29:37 +08:00
|
|
|
int ret;
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2018-02-14 04:13:46 +08:00
|
|
|
if (iattr->ia_valid & ATTR_MODE) {
|
|
|
|
if (iattr->ia_mode & (S_ISVTX)) {
|
|
|
|
if (is_root_handle(inode)) {
|
|
|
|
/*
|
|
|
|
* allow sticky bit to be set on root (since
|
|
|
|
* it shows up that way by default anyhow),
|
|
|
|
* but don't show it to the server
|
|
|
|
*/
|
|
|
|
iattr->ia_mode -= S_ISVTX;
|
|
|
|
} else {
|
|
|
|
gossip_debug(GOSSIP_UTILS_DEBUG,
|
|
|
|
"User attempted to set sticky bit on non-root directory; returning EINVAL.\n");
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2018-02-14 04:13:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iattr->ia_mode & (S_ISUID)) {
|
|
|
|
gossip_debug(GOSSIP_UTILS_DEBUG,
|
|
|
|
"Attempting to set setuid bit (not supported); returning EINVAL.\n");
|
2019-02-13 04:19:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2018-02-14 04:13:46 +08:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2017-04-26 03:38:04 +08:00
|
|
|
if (iattr->ia_valid & ATTR_SIZE) {
|
2015-11-25 04:12:14 +08:00
|
|
|
ret = orangefs_setattr_size(inode, iattr);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-02-14 04:13:46 +08:00
|
|
|
again:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (ORANGEFS_I(inode)->attr_valid) {
|
|
|
|
if (uid_eq(ORANGEFS_I(inode)->attr_uid, current_fsuid()) &&
|
|
|
|
gid_eq(ORANGEFS_I(inode)->attr_gid, current_fsgid())) {
|
|
|
|
ORANGEFS_I(inode)->attr_valid = iattr->ia_valid;
|
|
|
|
} else {
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
write_inode_now(inode, 1);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ORANGEFS_I(inode)->attr_valid = iattr->ia_valid;
|
|
|
|
ORANGEFS_I(inode)->attr_uid = current_fsuid();
|
|
|
|
ORANGEFS_I(inode)->attr_gid = current_fsgid();
|
|
|
|
}
|
2021-01-21 21:19:26 +08:00
|
|
|
setattr_copy(&init_user_ns, inode, iattr);
|
2018-02-14 04:13:46 +08:00
|
|
|
spin_unlock(&inode->i_lock);
|
2015-07-17 22:38:12 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
|
2018-02-13 04:29:37 +08:00
|
|
|
if (iattr->ia_valid & ATTR_MODE)
|
2015-07-17 22:38:12 +08:00
|
|
|
/* change mod on a file that has ACLs */
|
|
|
|
ret = posix_acl_chmod(inode, inode->i_mode);
|
|
|
|
|
2018-02-13 04:29:37 +08:00
|
|
|
ret = 0;
|
2015-07-17 22:38:12 +08:00
|
|
|
out:
|
2018-02-14 04:13:46 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change attributes of an object referenced by dentry.
|
|
|
|
*/
|
|
|
|
int orangefs_setattr(struct dentry *dentry, struct iattr *iattr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG, "__orangefs_setattr: called on %pd\n",
|
|
|
|
dentry);
|
2021-01-21 21:19:26 +08:00
|
|
|
ret = setattr_prepare(&init_user_ns, dentry, iattr);
|
2018-02-14 04:13:46 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = __orangefs_setattr(d_inode(dentry), iattr);
|
|
|
|
sync_inode_metadata(d_inode(dentry), 1);
|
|
|
|
out:
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_setattr: returning %d\n",
|
|
|
|
ret);
|
2015-07-17 22:38:12 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Obtain attributes of an object given a dentry
|
|
|
|
*/
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-02-01 00:46:22 +08:00
|
|
|
int orangefs_getattr(const struct path *path, struct kstat *stat,
|
|
|
|
u32 request_mask, unsigned int flags)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2019-07-29 02:04:07 +08:00
|
|
|
int ret;
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-02-01 00:46:22 +08:00
|
|
|
struct inode *inode = path->dentry->d_inode;
|
2015-07-17 22:38:12 +08:00
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
2018-02-13 01:04:57 +08:00
|
|
|
"orangefs_getattr: called on %pd mask %u\n",
|
|
|
|
path->dentry, request_mask);
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2018-02-08 02:44:50 +08:00
|
|
|
ret = orangefs_inode_getattr(inode,
|
|
|
|
request_mask & STATX_SIZE ? ORANGEFS_GETATTR_SIZE : 0);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (ret == 0) {
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-02-01 00:46:22 +08:00
|
|
|
generic_fillattr(inode, stat);
|
2016-03-15 03:30:03 +08:00
|
|
|
|
2015-07-17 22:38:12 +08:00
|
|
|
/* override block size reported to stat */
|
2019-01-21 23:23:25 +08:00
|
|
|
if (!(request_mask & STATX_SIZE))
|
|
|
|
stat->result_mask &= ~STATX_SIZE;
|
2018-06-01 00:37:00 +08:00
|
|
|
|
|
|
|
stat->attributes_mask = STATX_ATTR_IMMUTABLE |
|
|
|
|
STATX_ATTR_APPEND;
|
|
|
|
if (inode->i_flags & S_IMMUTABLE)
|
|
|
|
stat->attributes |= STATX_ATTR_IMMUTABLE;
|
|
|
|
if (inode->i_flags & S_APPEND)
|
|
|
|
stat->attributes |= STATX_ATTR_APPEND;
|
2015-07-17 22:38:12 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-31 02:46:54 +08:00
|
|
|
int orangefs_permission(struct inode *inode, int mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (mask & MAY_NOT_BLOCK)
|
|
|
|
return -ECHILD;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG, "%s: refreshing\n", __func__);
|
|
|
|
|
|
|
|
/* Make sure the permission (and other common attrs) are up to date. */
|
2018-02-08 02:44:50 +08:00
|
|
|
ret = orangefs_inode_getattr(inode, 0);
|
2016-01-31 02:46:54 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2021-01-21 21:19:24 +08:00
|
|
|
return generic_permission(&init_user_ns, inode, mask);
|
2016-01-31 02:46:54 +08:00
|
|
|
}
|
|
|
|
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
int orangefs_update_time(struct inode *inode, struct timespec64 *time, int flags)
|
2017-11-08 04:01:40 +08:00
|
|
|
{
|
|
|
|
struct iattr iattr;
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_update_time: %pU\n",
|
|
|
|
get_khandle_from_ino(inode));
|
|
|
|
generic_update_time(inode, time, flags);
|
|
|
|
memset(&iattr, 0, sizeof iattr);
|
|
|
|
if (flags & S_ATIME)
|
|
|
|
iattr.ia_valid |= ATTR_ATIME;
|
|
|
|
if (flags & S_CTIME)
|
|
|
|
iattr.ia_valid |= ATTR_CTIME;
|
|
|
|
if (flags & S_MTIME)
|
|
|
|
iattr.ia_valid |= ATTR_MTIME;
|
2018-02-14 04:13:46 +08:00
|
|
|
return __orangefs_setattr(inode, &iattr);
|
2017-11-08 04:01:40 +08:00
|
|
|
}
|
|
|
|
|
2018-05-12 05:11:48 +08:00
|
|
|
/* ORANGEFS2 implementation of VFS inode operations for files */
|
2018-04-04 00:27:13 +08:00
|
|
|
static const struct inode_operations orangefs_file_inode_operations = {
|
2015-11-25 04:12:14 +08:00
|
|
|
.get_acl = orangefs_get_acl,
|
|
|
|
.set_acl = orangefs_set_acl,
|
|
|
|
.setattr = orangefs_setattr,
|
|
|
|
.getattr = orangefs_getattr,
|
|
|
|
.listxattr = orangefs_listxattr,
|
2016-01-31 02:46:54 +08:00
|
|
|
.permission = orangefs_permission,
|
2017-11-08 04:01:40 +08:00
|
|
|
.update_time = orangefs_update_time,
|
2015-07-17 22:38:12 +08:00
|
|
|
};
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
static int orangefs_init_iops(struct inode *inode)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2015-11-25 04:12:14 +08:00
|
|
|
inode->i_mapping->a_ops = &orangefs_address_operations;
|
2015-07-17 22:38:12 +08:00
|
|
|
|
|
|
|
switch (inode->i_mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
2015-11-25 04:12:14 +08:00
|
|
|
inode->i_op = &orangefs_file_inode_operations;
|
|
|
|
inode->i_fop = &orangefs_file_operations;
|
2015-07-17 22:38:12 +08:00
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
2015-11-25 04:12:14 +08:00
|
|
|
inode->i_op = &orangefs_symlink_inode_operations;
|
2015-07-17 22:38:12 +08:00
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
2015-11-25 04:12:14 +08:00
|
|
|
inode->i_op = &orangefs_dir_inode_operations;
|
|
|
|
inode->i_fop = &orangefs_dir_operations;
|
2015-07-17 22:38:12 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
|
|
|
"%s: unsupported mode\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-05-12 05:11:48 +08:00
|
|
|
* Given an ORANGEFS object identifier (fsid, handle), convert it into
|
|
|
|
* a ino_t type that will be used as a hash-index from where the handle will
|
2015-07-17 22:38:12 +08:00
|
|
|
* be searched for in the VFS hash table of inodes.
|
|
|
|
*/
|
2015-11-25 04:12:14 +08:00
|
|
|
static inline ino_t orangefs_handle_hash(struct orangefs_object_kref *ref)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
|
|
|
if (!ref)
|
|
|
|
return 0;
|
2015-11-25 04:12:14 +08:00
|
|
|
return orangefs_khandle_to_ino(&(ref->khandle));
|
2015-07-17 22:38:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set up an inode from iget5_locked.
|
|
|
|
*/
|
2015-11-25 04:12:14 +08:00
|
|
|
static int orangefs_set_inode(struct inode *inode, void *data)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2015-11-25 04:12:14 +08:00
|
|
|
struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data;
|
2016-03-17 02:35:21 +08:00
|
|
|
ORANGEFS_I(inode)->refn.fs_id = ref->fs_id;
|
|
|
|
ORANGEFS_I(inode)->refn.khandle = ref->khandle;
|
2018-02-14 04:13:46 +08:00
|
|
|
ORANGEFS_I(inode)->attr_valid = 0;
|
2017-12-13 02:46:30 +08:00
|
|
|
hash_init(ORANGEFS_I(inode)->xattr_cache);
|
2019-02-13 04:19:06 +08:00
|
|
|
ORANGEFS_I(inode)->mapping_time = jiffies - 1;
|
|
|
|
ORANGEFS_I(inode)->bitlock = 0;
|
2015-07-17 22:38:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to determine if handles match.
|
|
|
|
*/
|
2015-11-25 04:12:14 +08:00
|
|
|
static int orangefs_test_inode(struct inode *inode, void *data)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2015-11-25 04:12:14 +08:00
|
|
|
struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data;
|
|
|
|
struct orangefs_inode_s *orangefs_inode = NULL;
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
orangefs_inode = ORANGEFS_I(inode);
|
2018-05-12 05:11:48 +08:00
|
|
|
/* test handles and fs_ids... */
|
|
|
|
return (!ORANGEFS_khandle_cmp(&(orangefs_inode->refn.khandle),
|
|
|
|
&(ref->khandle)) &&
|
|
|
|
orangefs_inode->refn.fs_id == ref->fs_id);
|
2015-07-17 22:38:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-11-25 04:12:14 +08:00
|
|
|
* Front-end to lookup the inode-cache maintained by the VFS using the ORANGEFS
|
2015-07-17 22:38:12 +08:00
|
|
|
* file handle.
|
|
|
|
*
|
|
|
|
* @sb: the file system super block instance.
|
2018-05-12 05:11:48 +08:00
|
|
|
* @ref: The ORANGEFS object for which we are trying to locate an inode.
|
2015-07-17 22:38:12 +08:00
|
|
|
*/
|
2018-05-12 05:11:48 +08:00
|
|
|
struct inode *orangefs_iget(struct super_block *sb,
|
|
|
|
struct orangefs_object_kref *ref)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
unsigned long hash;
|
|
|
|
int error;
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
hash = orangefs_handle_hash(ref);
|
2018-05-12 05:11:48 +08:00
|
|
|
inode = iget5_locked(sb,
|
|
|
|
hash,
|
|
|
|
orangefs_test_inode,
|
|
|
|
orangefs_set_inode,
|
|
|
|
ref);
|
2018-10-19 01:52:23 +08:00
|
|
|
|
|
|
|
if (!inode)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
if (!(inode->i_state & I_NEW))
|
2015-07-17 22:38:12 +08:00
|
|
|
return inode;
|
|
|
|
|
2018-02-08 02:44:50 +08:00
|
|
|
error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (error) {
|
|
|
|
iget_failed(inode);
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
inode->i_ino = hash; /* needed for stat etc */
|
2015-11-25 04:12:14 +08:00
|
|
|
orangefs_init_iops(inode);
|
2015-07-17 22:38:12 +08:00
|
|
|
unlock_new_inode(inode);
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
|
|
|
"iget handle %pU, fsid %d hash %ld i_ino %lu\n",
|
|
|
|
&ref->khandle,
|
|
|
|
ref->fs_id,
|
|
|
|
hash,
|
|
|
|
inode->i_ino);
|
|
|
|
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an inode for a newly created file and insert it into the inode hash.
|
|
|
|
*/
|
2015-11-25 04:12:14 +08:00
|
|
|
struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir,
|
|
|
|
int mode, dev_t dev, struct orangefs_object_kref *ref)
|
2015-07-17 22:38:12 +08:00
|
|
|
{
|
2015-11-25 04:12:14 +08:00
|
|
|
unsigned long hash = orangefs_handle_hash(ref);
|
2015-07-17 22:38:12 +08:00
|
|
|
struct inode *inode;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
2016-02-17 06:09:09 +08:00
|
|
|
"%s:(sb is %p | MAJOR(dev)=%u | MINOR(dev)=%u mode=%o)\n",
|
|
|
|
__func__,
|
2015-07-17 22:38:12 +08:00
|
|
|
sb,
|
|
|
|
MAJOR(dev),
|
|
|
|
MINOR(dev),
|
|
|
|
mode);
|
|
|
|
|
|
|
|
inode = new_inode(sb);
|
|
|
|
if (!inode)
|
2018-10-19 01:47:16 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2015-07-17 22:38:12 +08:00
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
orangefs_set_inode(inode, ref);
|
2015-07-17 22:38:12 +08:00
|
|
|
inode->i_ino = hash; /* needed for stat etc */
|
|
|
|
|
2018-02-08 02:44:50 +08:00
|
|
|
error = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_NEW);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (error)
|
|
|
|
goto out_iput;
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
orangefs_init_iops(inode);
|
2015-07-17 22:38:12 +08:00
|
|
|
inode->i_rdev = dev;
|
|
|
|
|
2015-11-25 04:12:14 +08:00
|
|
|
error = insert_inode_locked4(inode, hash, orangefs_test_inode, ref);
|
2015-07-17 22:38:12 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto out_iput;
|
|
|
|
|
|
|
|
gossip_debug(GOSSIP_INODE_DEBUG,
|
|
|
|
"Initializing ACL's for inode %pU\n",
|
|
|
|
get_khandle_from_ino(inode));
|
2015-11-25 04:12:14 +08:00
|
|
|
orangefs_init_acl(inode, dir);
|
2015-07-17 22:38:12 +08:00
|
|
|
return inode;
|
|
|
|
|
|
|
|
out_iput:
|
|
|
|
iput(inode);
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|