Skip to content

Commit c4fac91

Browse files
dhowellsAl Viro
authored andcommitted
9p: Implement show_options
Implement the show_options superblock op for 9p as part of a bid to get rid of s_options and generic_show_options() to make it easier to implement a context-based mount where the mount options can be passed individually over a file descriptor. Signed-off-by: David Howells <dhowells@redhat.com> cc: Eric Van Hensbergen <ericvh@gmail.com> cc: Ron Minnich <rminnich@sandia.gov> cc: Latchesar Ionkov <lucho@ionkov.net> cc: v9fs-developer@lists.sourceforge.net Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 86a1da6 commit c4fac91

File tree

8 files changed

+161
-10
lines changed

8 files changed

+161
-10
lines changed

fs/9p/v9fs.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/parser.h>
3434
#include <linux/idr.h>
3535
#include <linux/slab.h>
36+
#include <linux/seq_file.h>
3637
#include <net/9p/9p.h>
3738
#include <net/9p/client.h>
3839
#include <net/9p/transport.h>
@@ -82,6 +83,13 @@ static const match_table_t tokens = {
8283
{Opt_err, NULL}
8384
};
8485

86+
static const char *const v9fs_cache_modes[nr__p9_cache_modes] = {
87+
[CACHE_NONE] = "none",
88+
[CACHE_MMAP] = "mmap",
89+
[CACHE_LOOSE] = "loose",
90+
[CACHE_FSCACHE] = "fscache",
91+
};
92+
8593
/* Interpret mount options for cache mode */
8694
static int get_cache_mode(char *s)
8795
{
@@ -104,6 +112,58 @@ static int get_cache_mode(char *s)
104112
return version;
105113
}
106114

115+
/*
116+
* Display the mount options in /proc/mounts.
117+
*/
118+
int v9fs_show_options(struct seq_file *m, struct dentry *root)
119+
{
120+
struct v9fs_session_info *v9ses = root->d_sb->s_fs_info;
121+
122+
if (v9ses->debug)
123+
seq_printf(m, ",debug=%x", v9ses->debug);
124+
if (!uid_eq(v9ses->dfltuid, V9FS_DEFUID))
125+
seq_printf(m, ",dfltuid=%u",
126+
from_kuid_munged(&init_user_ns, v9ses->dfltuid));
127+
if (!gid_eq(v9ses->dfltgid, V9FS_DEFGID))
128+
seq_printf(m, ",dfltgid=%u",
129+
from_kgid_munged(&init_user_ns, v9ses->dfltgid));
130+
if (v9ses->afid != ~0)
131+
seq_printf(m, ",afid=%u", v9ses->afid);
132+
if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
133+
seq_printf(m, ",uname=%s", v9ses->uname);
134+
if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
135+
seq_printf(m, ",aname=%s", v9ses->aname);
136+
if (v9ses->nodev)
137+
seq_puts(m, ",nodevmap");
138+
if (v9ses->cache)
139+
seq_printf(m, ",%s", v9fs_cache_modes[v9ses->cache]);
140+
#ifdef CONFIG_9P_FSCACHE
141+
if (v9ses->cachetag && v9ses->cache == CACHE_FSCACHE)
142+
seq_printf(m, ",cachetag=%s", v9ses->cachetag);
143+
#endif
144+
145+
switch (v9ses->flags & V9FS_ACCESS_MASK) {
146+
case V9FS_ACCESS_USER:
147+
seq_puts(m, ",access=user");
148+
break;
149+
case V9FS_ACCESS_ANY:
150+
seq_puts(m, ",access=any");
151+
break;
152+
case V9FS_ACCESS_CLIENT:
153+
seq_puts(m, ",access=client");
154+
break;
155+
case V9FS_ACCESS_SINGLE:
156+
seq_printf(m, ",access=%u",
157+
from_kuid_munged(&init_user_ns, v9ses->uid));
158+
break;
159+
}
160+
161+
if (v9ses->flags & V9FS_POSIX_ACL)
162+
seq_puts(m, ",posixacl");
163+
164+
return p9_show_client_options(m, v9ses->clnt);
165+
}
166+
107167
/**
108168
* v9fs_parse_options - parse mount options into session structure
109169
* @v9ses: existing v9fs session information
@@ -230,6 +290,7 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
230290
break;
231291
case Opt_cachetag:
232292
#ifdef CONFIG_9P_FSCACHE
293+
kfree(v9ses->cachetag);
233294
v9ses->cachetag = match_strdup(&args[0]);
234295
#endif
235296
break;

fs/9p/v9fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum p9_cache_modes {
6767
CACHE_MMAP,
6868
CACHE_LOOSE,
6969
CACHE_FSCACHE,
70+
nr__p9_cache_modes
7071
};
7172

7273
/**
@@ -137,6 +138,8 @@ static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
137138
return container_of(inode, struct v9fs_inode, vfs_inode);
138139
}
139140

141+
extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
142+
140143
struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
141144
char *);
142145
extern void v9fs_session_close(struct v9fs_session_info *v9ses);

fs/9p/vfs_super.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <linux/string.h>
3434
#include <linux/inet.h>
3535
#include <linux/pagemap.h>
36-
#include <linux/seq_file.h>
3736
#include <linux/mount.h>
3837
#include <linux/idr.h>
3938
#include <linux/sched.h>
@@ -104,7 +103,6 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
104103
sb->s_flags |= MS_POSIXACL;
105104
#endif
106105

107-
save_mount_options(sb, data);
108106
return 0;
109107
}
110108

@@ -349,7 +347,7 @@ static const struct super_operations v9fs_super_ops = {
349347
.destroy_inode = v9fs_destroy_inode,
350348
.statfs = simple_statfs,
351349
.evict_inode = v9fs_evict_inode,
352-
.show_options = generic_show_options,
350+
.show_options = v9fs_show_options,
353351
.umount_begin = v9fs_umount_begin,
354352
.write_inode = v9fs_write_inode,
355353
};
@@ -360,7 +358,7 @@ static const struct super_operations v9fs_super_ops_dotl = {
360358
.statfs = v9fs_statfs,
361359
.drop_inode = v9fs_drop_inode,
362360
.evict_inode = v9fs_evict_inode,
363-
.show_options = generic_show_options,
361+
.show_options = v9fs_show_options,
364362
.umount_begin = v9fs_umount_begin,
365363
.write_inode = v9fs_write_inode_dotl,
366364
};

include/net/9p/client.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ struct p9_client {
157157
enum p9_trans_status status;
158158
void *trans;
159159

160+
union {
161+
struct {
162+
int rfd;
163+
int wfd;
164+
} fd;
165+
struct {
166+
u16 port;
167+
bool privport;
168+
169+
} tcp;
170+
} trans_opts;
171+
160172
struct p9_idpool *fidpool;
161173
struct list_head fidlist;
162174

@@ -213,6 +225,7 @@ struct p9_dirent {
213225

214226
struct iov_iter;
215227

228+
int p9_show_client_options(struct seq_file *m, struct p9_client *clnt);
216229
int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
217230
int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
218231
const char *name);

include/net/9p/transport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct p9_trans_module {
6262
int (*cancelled)(struct p9_client *, struct p9_req_t *req);
6363
int (*zc_request)(struct p9_client *, struct p9_req_t *,
6464
struct iov_iter *, struct iov_iter *, int , int, int);
65+
int (*show_options)(struct seq_file *, struct p9_client *);
6566
};
6667

6768
void v9fs_register_trans(struct p9_trans_module *m);

net/9p/client.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/uio.h>
3838
#include <net/9p/9p.h>
3939
#include <linux/parser.h>
40+
#include <linux/seq_file.h>
4041
#include <net/9p/client.h>
4142
#include <net/9p/transport.h>
4243
#include "protocol.h"
@@ -77,6 +78,30 @@ inline int p9_is_proto_dotu(struct p9_client *clnt)
7778
}
7879
EXPORT_SYMBOL(p9_is_proto_dotu);
7980

81+
int p9_show_client_options(struct seq_file *m, struct p9_client *clnt)
82+
{
83+
if (clnt->msize != 8192)
84+
seq_printf(m, ",msize=%u", clnt->msize);
85+
seq_printf(m, "trans=%s", clnt->trans_mod->name);
86+
87+
switch (clnt->proto_version) {
88+
case p9_proto_legacy:
89+
seq_puts(m, ",noextend");
90+
break;
91+
case p9_proto_2000u:
92+
seq_puts(m, ",version=9p2000.u");
93+
break;
94+
case p9_proto_2000L:
95+
/* Default */
96+
break;
97+
}
98+
99+
if (clnt->trans_mod->show_options)
100+
return clnt->trans_mod->show_options(m, clnt);
101+
return 0;
102+
}
103+
EXPORT_SYMBOL(p9_show_client_options);
104+
80105
/*
81106
* Some error codes are taken directly from the server replies,
82107
* make sure they are valid.

net/9p/trans_fd.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/file.h>
4242
#include <linux/parser.h>
4343
#include <linux/slab.h>
44+
#include <linux/seq_file.h>
4445
#include <net/9p/9p.h>
4546
#include <net/9p/client.h>
4647
#include <net/9p/transport.h>
@@ -51,6 +52,9 @@
5152
#define MAX_SOCK_BUF (64*1024)
5253
#define MAXPOLLWADDR 2
5354

55+
static struct p9_trans_module p9_tcp_trans;
56+
static struct p9_trans_module p9_fd_trans;
57+
5458
/**
5559
* struct p9_fd_opts - per-transport options
5660
* @rfd: file descriptor for reading (trans=fd)
@@ -63,7 +67,7 @@ struct p9_fd_opts {
6367
int rfd;
6468
int wfd;
6569
u16 port;
66-
int privport;
70+
bool privport;
6771
};
6872

6973
/*
@@ -720,6 +724,20 @@ static int p9_fd_cancelled(struct p9_client *client, struct p9_req_t *req)
720724
return 0;
721725
}
722726

727+
static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt)
728+
{
729+
if (clnt->trans_mod == &p9_tcp_trans) {
730+
if (clnt->trans_opts.tcp.port != P9_PORT)
731+
seq_printf(m, "port=%u", clnt->trans_opts.tcp.port);
732+
} else if (clnt->trans_mod == &p9_fd_trans) {
733+
if (clnt->trans_opts.fd.rfd != ~0)
734+
seq_printf(m, "rfd=%u", clnt->trans_opts.fd.rfd);
735+
if (clnt->trans_opts.fd.wfd != ~0)
736+
seq_printf(m, "wfd=%u", clnt->trans_opts.fd.wfd);
737+
}
738+
return 0;
739+
}
740+
723741
/**
724742
* parse_opts - parse mount options into p9_fd_opts structure
725743
* @params: options string passed from mount
@@ -738,7 +756,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
738756
opts->port = P9_PORT;
739757
opts->rfd = ~0;
740758
opts->wfd = ~0;
741-
opts->privport = 0;
759+
opts->privport = false;
742760

743761
if (!params)
744762
return 0;
@@ -776,7 +794,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
776794
opts->wfd = option;
777795
break;
778796
case Opt_privport:
779-
opts->privport = 1;
797+
opts->privport = true;
780798
break;
781799
default:
782800
continue;
@@ -942,6 +960,8 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
942960

943961
csocket = NULL;
944962

963+
client->trans_opts.tcp.port = opts.port;
964+
client->trans_opts.tcp.privport = opts.privport;
945965
sin_server.sin_family = AF_INET;
946966
sin_server.sin_addr.s_addr = in_aton(addr);
947967
sin_server.sin_port = htons(opts.port);
@@ -1020,6 +1040,8 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args)
10201040
struct p9_fd_opts opts;
10211041

10221042
parse_opts(args, &opts);
1043+
client->trans_opts.fd.rfd = opts.rfd;
1044+
client->trans_opts.fd.wfd = opts.wfd;
10231045

10241046
if (opts.rfd == ~0 || opts.wfd == ~0) {
10251047
pr_err("Insufficient options for proto=fd\n");
@@ -1044,6 +1066,7 @@ static struct p9_trans_module p9_tcp_trans = {
10441066
.request = p9_fd_request,
10451067
.cancel = p9_fd_cancel,
10461068
.cancelled = p9_fd_cancelled,
1069+
.show_options = p9_fd_show_options,
10471070
.owner = THIS_MODULE,
10481071
};
10491072

@@ -1056,6 +1079,7 @@ static struct p9_trans_module p9_unix_trans = {
10561079
.request = p9_fd_request,
10571080
.cancel = p9_fd_cancel,
10581081
.cancelled = p9_fd_cancelled,
1082+
.show_options = p9_fd_show_options,
10591083
.owner = THIS_MODULE,
10601084
};
10611085

@@ -1068,6 +1092,7 @@ static struct p9_trans_module p9_fd_trans = {
10681092
.request = p9_fd_request,
10691093
.cancel = p9_fd_cancel,
10701094
.cancelled = p9_fd_cancelled,
1095+
.show_options = p9_fd_show_options,
10711096
.owner = THIS_MODULE,
10721097
};
10731098

0 commit comments

Comments
 (0)