Skip to content

Commit f88657c

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: Add OS dependent open flags in 9p protocol
Some of the flags are OS/arch dependent we add a 9p protocol value which maps to asm-generic/fcntl.h values in Linux Based on the original patch from Venkateswararao Jujjuri <[email protected]> Signed-off-by: Aneesh Kumar K.V <[email protected]>
1 parent b49d8b5 commit f88657c

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

fs/9p/v9fs_vfs.h

+2
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@ static inline void v9fs_invalidate_inode_attr(struct inode *inode)
8383
v9inode->cache_validity |= V9FS_INO_INVALID_ATTR;
8484
return;
8585
}
86+
87+
int v9fs_open_to_dotl_flags(int flags);
8688
#endif

fs/9p/vfs_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
6565
v9inode = V9FS_I(inode);
6666
v9ses = v9fs_inode2v9ses(inode);
6767
if (v9fs_proto_dotl(v9ses))
68-
omode = file->f_flags;
68+
omode = v9fs_open_to_dotl_flags(file->f_flags);
6969
else
7070
omode = v9fs_uflags2omode(file->f_flags,
7171
v9fs_proto_dotu(v9ses));

fs/9p/vfs_inode.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,19 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
552552
return inode;
553553
}
554554

555+
/**
556+
* v9fs_at_to_dotl_flags- convert Linux specific AT flags to
557+
* plan 9 AT flag.
558+
* @flags: flags to convert
559+
*/
560+
static int v9fs_at_to_dotl_flags(int flags)
561+
{
562+
int rflags = 0;
563+
if (flags & AT_REMOVEDIR)
564+
rflags |= P9_DOTL_AT_REMOVEDIR;
565+
return rflags;
566+
}
567+
555568
/**
556569
* v9fs_remove - helper function to remove files and directories
557570
* @dir: directory inode that is being deleted
@@ -579,7 +592,8 @@ static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
579592
return retval;
580593
}
581594
if (v9fs_proto_dotl(v9ses))
582-
retval = p9_client_unlinkat(dfid, dentry->d_name.name, flags);
595+
retval = p9_client_unlinkat(dfid, dentry->d_name.name,
596+
v9fs_at_to_dotl_flags(flags));
583597
if (retval == -EOPNOTSUPP) {
584598
/* Try the one based on path */
585599
v9fid = v9fs_fid_clone(dentry);

fs/9p/vfs_inode_dotl.c

+54-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,58 @@ v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
191191
return inode;
192192
}
193193

194+
struct dotl_openflag_map {
195+
int open_flag;
196+
int dotl_flag;
197+
};
198+
199+
static int v9fs_mapped_dotl_flags(int flags)
200+
{
201+
int i;
202+
int rflags = 0;
203+
struct dotl_openflag_map dotl_oflag_map[] = {
204+
{ O_CREAT, P9_DOTL_CREATE },
205+
{ O_EXCL, P9_DOTL_EXCL },
206+
{ O_NOCTTY, P9_DOTL_NOCTTY },
207+
{ O_TRUNC, P9_DOTL_TRUNC },
208+
{ O_APPEND, P9_DOTL_APPEND },
209+
{ O_NONBLOCK, P9_DOTL_NONBLOCK },
210+
{ O_DSYNC, P9_DOTL_DSYNC },
211+
{ FASYNC, P9_DOTL_FASYNC },
212+
{ O_DIRECT, P9_DOTL_DIRECT },
213+
{ O_LARGEFILE, P9_DOTL_LARGEFILE },
214+
{ O_DIRECTORY, P9_DOTL_DIRECTORY },
215+
{ O_NOFOLLOW, P9_DOTL_NOFOLLOW },
216+
{ O_NOATIME, P9_DOTL_NOATIME },
217+
{ O_CLOEXEC, P9_DOTL_CLOEXEC },
218+
{ O_SYNC, P9_DOTL_SYNC},
219+
};
220+
for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
221+
if (flags & dotl_oflag_map[i].open_flag)
222+
rflags |= dotl_oflag_map[i].dotl_flag;
223+
}
224+
return rflags;
225+
}
226+
227+
/**
228+
* v9fs_open_to_dotl_flags- convert Linux specific open flags to
229+
* plan 9 open flag.
230+
* @flags: flags to convert
231+
*/
232+
int v9fs_open_to_dotl_flags(int flags)
233+
{
234+
int rflags = 0;
235+
236+
/*
237+
* We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
238+
* and P9_DOTL_NOACCESS
239+
*/
240+
rflags |= flags & O_ACCMODE;
241+
rflags |= v9fs_mapped_dotl_flags(flags);
242+
243+
return rflags;
244+
}
245+
194246
/**
195247
* v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
196248
* @dir: directory inode that is being created
@@ -259,7 +311,8 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
259311
"Failed to get acl values in creat %d\n", err);
260312
goto error;
261313
}
262-
err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
314+
err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
315+
mode, gid, &qid);
263316
if (err < 0) {
264317
P9_DPRINTK(P9_DEBUG_VFS,
265318
"p9_client_open_dotl failed in creat %d\n",

include/net/9p/9p.h

+24
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,30 @@ enum p9_perm_t {
288288
P9_DMSETVTX = 0x00010000,
289289
};
290290

291+
/* 9p2000.L open flags */
292+
#define P9_DOTL_RDONLY 00000000
293+
#define P9_DOTL_WRONLY 00000001
294+
#define P9_DOTL_RDWR 00000002
295+
#define P9_DOTL_NOACCESS 00000003
296+
#define P9_DOTL_CREATE 00000100
297+
#define P9_DOTL_EXCL 00000200
298+
#define P9_DOTL_NOCTTY 00000400
299+
#define P9_DOTL_TRUNC 00001000
300+
#define P9_DOTL_APPEND 00002000
301+
#define P9_DOTL_NONBLOCK 00004000
302+
#define P9_DOTL_DSYNC 00010000
303+
#define P9_DOTL_FASYNC 00020000
304+
#define P9_DOTL_DIRECT 00040000
305+
#define P9_DOTL_LARGEFILE 00100000
306+
#define P9_DOTL_DIRECTORY 00200000
307+
#define P9_DOTL_NOFOLLOW 00400000
308+
#define P9_DOTL_NOATIME 01000000
309+
#define P9_DOTL_CLOEXEC 02000000
310+
#define P9_DOTL_SYNC 04000000
311+
312+
/* 9p2000.L at flags */
313+
#define P9_DOTL_AT_REMOVEDIR 0x200
314+
291315
/**
292316
* enum p9_qid_t - QID types
293317
* @P9_QTDIR: directory

0 commit comments

Comments
 (0)