// SPDX-License-Identifier: GPL-2.0 /* * (C) 2001 Clemson University and The University of Chicago * Copyright 2018 Omnibond Systems, L.L.C. * * See COPYING in top-level directory.
*/
if (!wr) {
folio_unlock(folio); /* It's not private so there's nothing to write, right? */
printk("writepages_callback not private!\n");
BUG(); return 0;
}
ret = -1; if (ow->nfolios == 0) {
ow->off = wr->pos;
ow->len = wr->len;
ow->uid = wr->uid;
ow->gid = wr->gid;
ow->folios[ow->nfolios++] = folio;
ret = 0; goto done;
} if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) {
orangefs_writepages_work(ow, wbc);
ow->nfolios = 0;
ret = -1; goto done;
} if (ow->off + ow->len == wr->pos) {
ow->len += wr->len;
ow->folios[ow->nfolios++] = folio;
ret = 0; goto done;
}
done: if (ret == -1) { if (ow->nfolios) {
orangefs_writepages_work(ow, wbc);
ow->nfolios = 0;
}
ret = orangefs_writepage_locked(folio, wbc);
mapping_set_error(folio->mapping, ret);
folio_unlock(folio);
folio_end_writeback(folio);
} else { if (ow->nfolios == ow->maxpages) {
orangefs_writepages_work(ow, wbc);
ow->nfolios = 0;
}
} return ret;
}
ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter,
folio_size(folio), inode->i_size, NULL, NULL, file); /* this will only zero remaining unread portions of the folio data */
iov_iter_zero(~0U, &iter); /* takes care of potential aliasing */
flush_dcache_folio(folio); if (ret > 0)
ret = 0;
folio_end_read(folio, ret == 0); return ret;
}
if (folio_test_dirty(folio) && !folio_test_private(folio)) { /* * 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_folio(folio); if (ret) return ret;
} if (folio_test_private(folio)) { struct orangefs_write_range *wr;
wr = folio_get_private(folio); if (wr->pos + wr->len == pos &&
uid_eq(wr->uid, current_fsuid()) &&
gid_eq(wr->gid, current_fsgid())) {
wr->len += len; goto okay;
} else {
wr->pos = pos;
wr->len = len;
ret = orangefs_launder_folio(folio); if (ret) return ret;
}
}
wr = kmalloc(sizeof *wr, GFP_KERNEL); if (!wr) return -ENOMEM;
/* * 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 folio if we did a short copy */ if (!folio_test_uptodate(folio)) { unsigned from = pos & (PAGE_SIZE - 1); if (copied < len) {
folio_zero_range(folio, from + copied, len - copied);
} /* Set fully written pages uptodate. */ if (pos == folio_pos(folio) &&
(len == PAGE_SIZE || pos + len == inode->i_size)) {
folio_zero_segment(folio, from + copied, PAGE_SIZE);
folio_mark_uptodate(folio);
}
}
staticint orangefs_launder_folio(struct folio *folio)
{ int r = 0; struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL,
.nr_to_write = 0,
};
folio_wait_writeback(folio); if (folio_clear_dirty_for_io(folio)) {
r = orangefs_writepage_locked(folio, &wbc);
folio_end_writeback(folio);
} return r;
}
static ssize_t orangefs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{ /* * 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.
*/ struct file *file = iocb->ki_filp;
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;
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;
/* 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,
each_count, 0, NULL, NULL, file);
gossip_debug(GOSSIP_FILE_DEBUG, "%s(%pU): return from wait_for_io:%d\n",
__func__,
handle,
(int)ret);
if (wait_on_bit(bitlock, 1, TASK_KILLABLE)) {
ret = VM_FAULT_RETRY; goto out;
}
folio_lock(folio); if (folio_test_dirty(folio) && !folio_test_private(folio)) { /* * Should be impossible. If it happens, launder the folio * since we don't know what's dirty. This will WARN in * orangefs_writepage_locked.
*/ if (orangefs_launder_folio(folio)) {
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; goto out;
}
} if (folio_test_private(folio)) {
wr = folio_get_private(folio); if (uid_eq(wr->uid, current_fsuid()) &&
gid_eq(wr->gid, current_fsgid())) {
wr->pos = page_offset(vmf->page);
wr->len = PAGE_SIZE; goto okay;
} else { if (orangefs_launder_folio(folio)) {
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; goto out;
}
}
}
wr = kmalloc(sizeof *wr, GFP_KERNEL); if (!wr) {
ret = VM_FAULT_LOCKED|VM_FAULT_RETRY; goto out;
}
wr->pos = page_offset(vmf->page);
wr->len = PAGE_SIZE;
wr->uid = current_fsuid();
wr->gid = current_fsgid();
folio_attach_private(folio, wr);
okay:
file_update_time(vmf->vma->vm_file); if (folio->mapping != inode->i_mapping) {
folio_unlock(folio);
ret = VM_FAULT_LOCKED|VM_FAULT_NOPAGE; goto out;
}
/* * We mark the folio dirty already here so that when freeze is in * progress, we are guaranteed that writeback during freezing will * see the dirty folio and writeprotect it again.
*/
folio_mark_dirty(folio);
folio_wait_stable(folio);
ret = VM_FAULT_LOCKED;
out:
sb_end_pagefault(inode->i_sb); return ret;
}
gossip_debug(GOSSIP_INODE_DEBUG, "%s: %pU: Handle is %pU | fs_id %d | size is %llu\n",
__func__,
get_khandle_from_ino(inode),
&orangefs_inode->refn.khandle,
orangefs_inode->refn.fs_id,
iattr->ia_size);
/* Ensure that we have a up to date size, so we know if it changed. */
ret = orangefs_inode_getattr(inode, ORANGEFS_GETATTR_SIZE); 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);
/* 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);
new_op = op_alloc(ORANGEFS_VFS_OP_TRUNCATE); if (!new_op) return -ENOMEM;
ret = service_operation(new_op,
__func__,
get_interruptible_flag(inode));
/* * the truncate has no downcall members to retrieve, but * the status value tells us if it went through ok or not
*/
gossip_debug(GOSSIP_INODE_DEBUG, "%s: ret:%d:\n", __func__, ret);
op_release(new_op);
if (ret != 0) return ret;
if (orig_size != i_size_read(inode))
iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
return ret;
}
int __orangefs_setattr(struct inode *inode, struct iattr *iattr)
{ int ret;
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");
ret = -EINVAL; goto out;
}
} if (iattr->ia_mode & (S_ISUID)) {
gossip_debug(GOSSIP_UTILS_DEBUG, "Attempting to set setuid bit (not supported); returning EINVAL.\n");
ret = -EINVAL; goto out;
}
}
if (iattr->ia_valid & ATTR_SIZE) {
ret = orangefs_setattr_size(inode, iattr); if (ret) goto out;
}
int __orangefs_setattr_mode(struct dentry *dentry, struct iattr *iattr)
{ int ret; struct inode *inode = d_inode(dentry);
ret = __orangefs_setattr(inode, iattr); /* change mode on a file that has ACLs */ if (!ret && (iattr->ia_valid & ATTR_MODE))
ret = posix_acl_chmod(&nop_mnt_idmap, dentry, inode->i_mode); return ret;
}
/* * Change attributes of an object referenced by dentry.
*/ int orangefs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *iattr)
{ int ret;
gossip_debug(GOSSIP_INODE_DEBUG, "__orangefs_setattr: called on %pd\n",
dentry);
ret = setattr_prepare(&nop_mnt_idmap, dentry, iattr); if (ret) goto out;
ret = __orangefs_setattr_mode(dentry, iattr);
sync_inode_metadata(d_inode(dentry), 1);
out:
gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_setattr: returning %d\n",
ret); return ret;
}
/* * Obtain attributes of an object given a dentry
*/ int orangefs_getattr(struct mnt_idmap *idmap, conststruct path *path, struct kstat *stat, u32 request_mask, unsignedint flags)
{ int ret; struct inode *inode = path->dentry->d_inode;
gossip_debug(GOSSIP_INODE_DEBUG, "orangefs_getattr: called on %pd mask %u\n",
path->dentry, request_mask);
ret = orangefs_inode_getattr(inode,
request_mask & STATX_SIZE ? ORANGEFS_GETATTR_SIZE : 0); if (ret == 0) {
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
/* override block size reported to stat */ if (!(request_mask & STATX_SIZE))
stat->result_mask &= ~STATX_SIZE;
gossip_debug(GOSSIP_FILE_DEBUG, "%s: called on %pd\n", __func__,
dentry); /* * ORANGEFS_MIRROR_FL is set internally when the mirroring mode is * turned on for a file. The user is not allowed to turn on this bit, * but the bit is present if the user first gets the flags and then * updates the flags with some new settings. So, we ignore it in the * following edit. bligon.
*/ if (fileattr_has_fsx(fa) ||
(fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL | ORANGEFS_MIRROR_FL))) {
gossip_err("%s: only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n",
__func__); return -EOPNOTSUPP;
}
val = fa->flags;
gossip_debug(GOSSIP_FILE_DEBUG, "%s: flags=%u\n", __func__, (u32) val); return orangefs_inode_setxattr(d_inode(dentry), "user.pvfs2.meta_hint",
&val, sizeof(val), 0);
}
/* * 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 * be searched for in the VFS hash table of inodes.
*/ staticinline ino_t orangefs_handle_hash(struct orangefs_object_kref *ref)
{ if (!ref) return 0; return orangefs_khandle_to_ino(&(ref->khandle));
}
/* * Called to set up an inode from iget5_locked.
*/ staticint orangefs_set_inode(struct inode *inode, void *data)
{ struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data;
ORANGEFS_I(inode)->refn.fs_id = ref->fs_id;
ORANGEFS_I(inode)->refn.khandle = ref->khandle;
ORANGEFS_I(inode)->attr_valid = 0;
hash_init(ORANGEFS_I(inode)->xattr_cache);
ORANGEFS_I(inode)->mapping_time = jiffies - 1;
ORANGEFS_I(inode)->bitlock = 0; return 0;
}
/* * Called to determine if handles match.
*/ staticint orangefs_test_inode(struct inode *inode, void *data)
{ struct orangefs_object_kref *ref = (struct orangefs_object_kref *) data; struct orangefs_inode_s *orangefs_inode = NULL;
orangefs_inode = ORANGEFS_I(inode); /* test handles and fs_ids... */ return (!ORANGEFS_khandle_cmp(&(orangefs_inode->refn.khandle),
&(ref->khandle)) &&
orangefs_inode->refn.fs_id == ref->fs_id);
}
/* * Front-end to lookup the inode-cache maintained by the VFS using the ORANGEFS * file handle. * * @sb: the file system super block instance. * @ref: The ORANGEFS object for which we are trying to locate an inode.
*/ struct inode *orangefs_iget(struct super_block *sb, struct orangefs_object_kref *ref)
{ struct inode *inode = NULL; unsignedlong hash; int error;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.