// SPDX-License-Identifier: GPL-2.0-only /* * Common helpers for stackable filesystems and backing files. * * Forked from fs/overlayfs/file.c. * * Copyright (C) 2017 Red Hat, Inc. * Copyright (C) 2023 CTERA Networks.
*/
/** * backing_file_open - open a backing file for kernel internal use * @user_path: path that the user reuqested to open * @flags: open flags * @real_path: path of the backing file * @cred: credentials for open * * Open a backing file for a stackable filesystem (e.g., overlayfs). * @user_path may be on the stackable filesystem and @real_path on the * underlying filesystem. In this case, we want to be able to return the * @user_path of the stackable filesystem. This is done by embedding the * returned file into a container structure that also stores the stacked * file's path, which can be retrieved using backing_file_user_path().
*/ struct file *backing_file_open(conststruct path *user_path, int flags, conststruct path *real_path, conststruct cred *cred)
{ struct file *f; int error;
f = alloc_empty_backing_file(flags, cred); if (IS_ERR(f)) return f;
path_get(user_path);
backing_file_set_user_path(f, user_path);
error = vfs_open(real_path, f); if (error) {
fput(f);
f = ERR_PTR(error);
}
/* * Punt to a work queue to serialize updates of mtime/size.
*/
aio->res = res;
INIT_WORK(&aio->work, backing_aio_complete_work);
queue_work(file_inode(aio->orig_iocb->ki_filp)->i_sb->s_dio_done_wq,
&aio->work);
}
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING))) return -EIO;
if (!iov_iter_count(iter)) return 0;
ret = file_remove_privs(iocb->ki_filp); if (ret) return ret;
if (iocb->ki_flags & IOCB_DIRECT &&
!(file->f_mode & FMODE_CAN_ODIRECT)) return -EINVAL;
/* * Stacked filesystems don't support deferred completions, don't copy * this property in case it is set by the issuer.
*/
flags &= ~IOCB_DIO_CALLER_COMP;
old_cred = override_creds(ctx->cred); if (is_sync_kiocb(iocb)) {
rwf_t rwf = iocb_to_rw_flags(flags);
ret = vfs_iter_write(file, iter, &iocb->ki_pos, rwf); if (ctx->end_write)
ctx->end_write(iocb, ret);
} else { struct backing_aio *aio;
ret = backing_aio_init_wq(iocb); if (ret) goto out;
ret = -ENOMEM;
aio = kmem_cache_zalloc(backing_aio_cachep, GFP_KERNEL); if (!aio) goto out;
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.