Skip to content

Commit 7d37539

Browse files
author
Miklos Szeredi
committed
fuse: implement ->tmpfile()
This is basically equivalent to the FUSE_CREATE operation which creates and opens a regular file. Add a new FUSE_TMPFILE operation, otherwise just reuse the protocol and the code for FUSE_CREATE. Acked-by: Christian Brauner (Microsoft) <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 863f144 commit 7d37539

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

fs/fuse/dir.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static int get_security_context(struct dentry *entry, umode_t mode,
529529
*/
530530
static int fuse_create_open(struct inode *dir, struct dentry *entry,
531531
struct file *file, unsigned int flags,
532-
umode_t mode)
532+
umode_t mode, u32 opcode)
533533
{
534534
int err;
535535
struct inode *inode;
@@ -573,7 +573,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
573573
inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
574574
}
575575

576-
args.opcode = FUSE_CREATE;
576+
args.opcode = opcode;
577577
args.nodeid = get_node_id(dir);
578578
args.in_numargs = 2;
579579
args.in_args[0].size = sizeof(inarg);
@@ -676,7 +676,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
676676
if (fc->no_create)
677677
goto mknod;
678678

679-
err = fuse_create_open(dir, entry, file, flags, mode);
679+
err = fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE);
680680
if (err == -ENOSYS) {
681681
fc->no_create = 1;
682682
goto mknod;
@@ -802,6 +802,23 @@ static int fuse_create(struct user_namespace *mnt_userns, struct inode *dir,
802802
return fuse_mknod(&init_user_ns, dir, entry, mode, 0);
803803
}
804804

805+
static int fuse_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
806+
struct file *file, umode_t mode)
807+
{
808+
struct fuse_conn *fc = get_fuse_conn(dir);
809+
int err;
810+
811+
if (fc->no_tmpfile)
812+
return -EOPNOTSUPP;
813+
814+
err = fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE);
815+
if (err == -ENOSYS) {
816+
fc->no_tmpfile = 1;
817+
err = -EOPNOTSUPP;
818+
}
819+
return err;
820+
}
821+
805822
static int fuse_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
806823
struct dentry *entry, umode_t mode)
807824
{
@@ -1913,6 +1930,7 @@ static const struct inode_operations fuse_dir_inode_operations = {
19131930
.setattr = fuse_setattr,
19141931
.create = fuse_create,
19151932
.atomic_open = fuse_atomic_open,
1933+
.tmpfile = fuse_tmpfile,
19161934
.mknod = fuse_mknod,
19171935
.permission = fuse_permission,
19181936
.getattr = fuse_getattr,

fs/fuse/fuse_i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ struct fuse_conn {
784784
/* Does the filesystem support per inode DAX? */
785785
unsigned int inode_dax:1;
786786

787+
/* Is tmpfile not implemented by fs? */
788+
unsigned int no_tmpfile:1;
789+
787790
/** The number of requests waiting for completion */
788791
atomic_t num_waiting;
789792

include/uapi/linux/fuse.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
* - add FUSE_SECURITY_CTX init flag
195195
* - add security context to create, mkdir, symlink, and mknod requests
196196
* - add FUSE_HAS_INODE_DAX, FUSE_ATTR_DAX
197+
*
198+
* 7.37
199+
* - add FUSE_TMPFILE
197200
*/
198201

199202
#ifndef _LINUX_FUSE_H
@@ -229,7 +232,7 @@
229232
#define FUSE_KERNEL_VERSION 7
230233

231234
/** Minor version number of this interface */
232-
#define FUSE_KERNEL_MINOR_VERSION 36
235+
#define FUSE_KERNEL_MINOR_VERSION 37
233236

234237
/** The node ID of the root inode */
235238
#define FUSE_ROOT_ID 1
@@ -537,6 +540,7 @@ enum fuse_opcode {
537540
FUSE_SETUPMAPPING = 48,
538541
FUSE_REMOVEMAPPING = 49,
539542
FUSE_SYNCFS = 50,
543+
FUSE_TMPFILE = 51,
540544

541545
/* CUSE specific operations */
542546
CUSE_INIT = 4096,

0 commit comments

Comments
 (0)