Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

9p: add 9P2000.L statfs operation

I made a V2 of this patch on top of my patches for VFS switches. The
change was adding v9fs_statfs pointer to v9fs_super_ops_dotl
instead of v9fs_super_ops.

statfs - get file system statistics

size[4] Tstatfs tag[2] fid[4]
size[4] Rstatfs tag[2] type[4] bsize[4] blocks[8] bfree[8] bavail[8]
files[8] ffree[8] fsid[8] namelen[4]

The statfs message is used to request file system information returned
by the statfs(2) system call, which is used by df(1) to report file
system and disk space usage.

Signed-off-by: Jim Garlick <garlick@llnl.gov>
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

authored by

Sripathi Kodi and committed by
Eric Van Hensbergen
bda8e775 9b6533c9

+98 -1
+38 -1
fs/9p/vfs_super.c
··· 38 38 #include <linux/idr.h> 39 39 #include <linux/sched.h> 40 40 #include <linux/slab.h> 41 + #include <linux/statfs.h> 41 42 #include <net/9p/9p.h> 42 43 #include <net/9p/client.h> 43 44 ··· 215 214 v9fs_session_begin_cancel(v9ses); 216 215 } 217 216 217 + static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf) 218 + { 219 + struct v9fs_session_info *v9ses; 220 + struct p9_fid *fid; 221 + struct p9_rstatfs rs; 222 + int res; 223 + 224 + fid = v9fs_fid_lookup(dentry); 225 + if (IS_ERR(fid)) { 226 + res = PTR_ERR(fid); 227 + goto done; 228 + } 229 + 230 + v9ses = v9fs_inode2v9ses(dentry->d_inode); 231 + if (v9fs_proto_dotl(v9ses)) { 232 + res = p9_client_statfs(fid, &rs); 233 + if (res == 0) { 234 + buf->f_type = rs.type; 235 + buf->f_bsize = rs.bsize; 236 + buf->f_blocks = rs.blocks; 237 + buf->f_bfree = rs.bfree; 238 + buf->f_bavail = rs.bavail; 239 + buf->f_files = rs.files; 240 + buf->f_ffree = rs.ffree; 241 + buf->f_fsid.val[0] = rs.fsid & 0xFFFFFFFFUL; 242 + buf->f_fsid.val[1] = (rs.fsid >> 32) & 0xFFFFFFFFUL; 243 + buf->f_namelen = rs.namelen; 244 + } 245 + if (res != -ENOSYS) 246 + goto done; 247 + } 248 + res = simple_statfs(dentry, buf); 249 + done: 250 + return res; 251 + } 252 + 218 253 static const struct super_operations v9fs_super_ops = { 219 254 #ifdef CONFIG_9P_FSCACHE 220 255 .alloc_inode = v9fs_alloc_inode, ··· 267 230 .alloc_inode = v9fs_alloc_inode, 268 231 .destroy_inode = v9fs_destroy_inode, 269 232 #endif 270 - .statfs = simple_statfs, 233 + .statfs = v9fs_statfs, 271 234 .clear_inode = v9fs_clear_inode, 272 235 .show_options = generic_show_options, 273 236 .umount_begin = v9fs_umount_begin,
+20
include/net/9p/9p.h
··· 86 86 87 87 /** 88 88 * enum p9_msg_t - 9P message types 89 + * @P9_TSTATFS: file system status request 90 + * @P9_RSTATFS: file system status response 89 91 * @P9_TVERSION: version handshake request 90 92 * @P9_RVERSION: version handshake response 91 93 * @P9_TAUTH: request to establish authentication channel ··· 127 125 */ 128 126 129 127 enum p9_msg_t { 128 + P9_TSTATFS = 8, 129 + P9_RSTATFS, 130 130 P9_TVERSION = 100, 131 131 P9_RVERSION, 132 132 P9_TAUTH = 102, ··· 354 350 }; 355 351 356 352 /* Structures for Protocol Operations */ 353 + struct p9_tstatfs { 354 + u32 fid; 355 + }; 356 + 357 + struct p9_rstatfs { 358 + u32 type; 359 + u32 bsize; 360 + u64 blocks; 361 + u64 bfree; 362 + u64 bavail; 363 + u64 files; 364 + u64 ffree; 365 + u64 fsid; 366 + u32 namelen; 367 + }; 368 + 357 369 struct p9_tversion { 358 370 u32 msize; 359 371 struct p9_str version;
+1
include/net/9p/client.h
··· 195 195 struct list_head dlist; /* list of all fids attached to a dentry */ 196 196 }; 197 197 198 + int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb); 198 199 int p9_client_version(struct p9_client *); 199 200 struct p9_client *p9_client_create(const char *dev_name, char *options); 200 201 void p9_client_destroy(struct p9_client *clnt);
+39
net/9p/client.c
··· 1365 1365 return err; 1366 1366 } 1367 1367 EXPORT_SYMBOL(p9_client_wstat); 1368 + 1369 + int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) 1370 + { 1371 + int err; 1372 + struct p9_req_t *req; 1373 + struct p9_client *clnt; 1374 + 1375 + err = 0; 1376 + clnt = fid->clnt; 1377 + 1378 + P9_DPRINTK(P9_DEBUG_9P, ">>> TSTATFS fid %d\n", fid->fid); 1379 + 1380 + req = p9_client_rpc(clnt, P9_TSTATFS, "d", fid->fid); 1381 + if (IS_ERR(req)) { 1382 + err = PTR_ERR(req); 1383 + goto error; 1384 + } 1385 + 1386 + err = p9pdu_readf(req->rc, clnt->proto_version, "ddqqqqqqd", &sb->type, 1387 + &sb->bsize, &sb->blocks, &sb->bfree, &sb->bavail, 1388 + &sb->files, &sb->ffree, &sb->fsid, &sb->namelen); 1389 + if (err) { 1390 + p9pdu_dump(1, req->rc); 1391 + p9_free_req(clnt, req); 1392 + goto error; 1393 + } 1394 + 1395 + P9_DPRINTK(P9_DEBUG_9P, "<<< RSTATFS fid %d type 0x%lx bsize %ld " 1396 + "blocks %llu bfree %llu bavail %llu files %llu ffree %llu " 1397 + "fsid %llu namelen %ld\n", 1398 + fid->fid, (long unsigned int)sb->type, (long int)sb->bsize, 1399 + sb->blocks, sb->bfree, sb->bavail, sb->files, sb->ffree, 1400 + sb->fsid, (long int)sb->namelen); 1401 + 1402 + p9_free_req(clnt, req); 1403 + error: 1404 + return err; 1405 + } 1406 + EXPORT_SYMBOL(p9_client_statfs);