diff options
author | Sripathi Kodi <sripathik@in.ibm.com> | 2010-06-04 09:41:26 -0400 |
---|---|---|
committer | Eric Van Hensbergen <ericvh@gmail.com> | 2010-08-02 15:25:07 -0400 |
commit | 7751bdb3a095ad32dd4fcff3443cf8dd4cb1e748 (patch) | |
tree | 6c7a93a546e34d86e433a1be05e3ebfcc4f77754 /net/9p | |
parent | 97e8442b0971ea6be9a495b3d03402985cfe5d6a (diff) |
9p: readdir implementation for 9p2000.L
This patch implements the kernel part of readdir() implementation for 9p2000.L
Change from V3: Instead of inode, server now sends qids for each dirent
SYNOPSIS
size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]
DESCRIPTION
The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.
qid.type[1]
the type of the file (directory, etc.), represented as a bit
vector corresponding to the high 8 bits of the file's mode
word.
qid.vers[4]
version number for given path
qid.path[8]
the file server's unique identification for the file
offset[8]
offset into the next dirent.
type[1]
type of this directory entry.
name[256]
name of this directory entry.
This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls >/dev/null' on a directory with 10000 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 seconds
with the new readdir.
Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'net/9p')
-rw-r--r-- | net/9p/client.c | 47 | ||||
-rw-r--r-- | net/9p/protocol.c | 27 |
2 files changed, 74 insertions, 0 deletions
diff --git a/net/9p/client.c b/net/9p/client.c index 37c8da07a80b..a80357483a47 100644 --- a/net/9p/client.c +++ b/net/9p/client.c | |||
@@ -1432,3 +1432,50 @@ error: | |||
1432 | } | 1432 | } |
1433 | EXPORT_SYMBOL(p9_client_rename); | 1433 | EXPORT_SYMBOL(p9_client_rename); |
1434 | 1434 | ||
1435 | int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset) | ||
1436 | { | ||
1437 | int err, rsize, total; | ||
1438 | struct p9_client *clnt; | ||
1439 | struct p9_req_t *req; | ||
1440 | char *dataptr; | ||
1441 | |||
1442 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n", | ||
1443 | fid->fid, (long long unsigned) offset, count); | ||
1444 | |||
1445 | err = 0; | ||
1446 | clnt = fid->clnt; | ||
1447 | total = 0; | ||
1448 | |||
1449 | rsize = fid->iounit; | ||
1450 | if (!rsize || rsize > clnt->msize-P9_READDIRHDRSZ) | ||
1451 | rsize = clnt->msize - P9_READDIRHDRSZ; | ||
1452 | |||
1453 | if (count < rsize) | ||
1454 | rsize = count; | ||
1455 | |||
1456 | req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, offset, rsize); | ||
1457 | if (IS_ERR(req)) { | ||
1458 | err = PTR_ERR(req); | ||
1459 | goto error; | ||
1460 | } | ||
1461 | |||
1462 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); | ||
1463 | if (err) { | ||
1464 | p9pdu_dump(1, req->rc); | ||
1465 | goto free_and_error; | ||
1466 | } | ||
1467 | |||
1468 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count); | ||
1469 | |||
1470 | if (data) | ||
1471 | memmove(data, dataptr, count); | ||
1472 | |||
1473 | p9_free_req(clnt, req); | ||
1474 | return count; | ||
1475 | |||
1476 | free_and_error: | ||
1477 | p9_free_req(clnt, req); | ||
1478 | error: | ||
1479 | return err; | ||
1480 | } | ||
1481 | EXPORT_SYMBOL(p9_client_readdir); | ||
diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 149f82160130..b645c8263538 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c | |||
@@ -580,3 +580,30 @@ void p9pdu_reset(struct p9_fcall *pdu) | |||
580 | pdu->offset = 0; | 580 | pdu->offset = 0; |
581 | pdu->size = 0; | 581 | pdu->size = 0; |
582 | } | 582 | } |
583 | |||
584 | int p9dirent_read(char *buf, int len, struct p9_dirent *dirent, | ||
585 | int proto_version) | ||
586 | { | ||
587 | struct p9_fcall fake_pdu; | ||
588 | int ret; | ||
589 | char *nameptr; | ||
590 | |||
591 | fake_pdu.size = len; | ||
592 | fake_pdu.capacity = len; | ||
593 | fake_pdu.sdata = buf; | ||
594 | fake_pdu.offset = 0; | ||
595 | |||
596 | ret = p9pdu_readf(&fake_pdu, proto_version, "Qqbs", &dirent->qid, | ||
597 | &dirent->d_off, &dirent->d_type, &nameptr); | ||
598 | if (ret) { | ||
599 | P9_DPRINTK(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret); | ||
600 | p9pdu_dump(1, &fake_pdu); | ||
601 | goto out; | ||
602 | } | ||
603 | |||
604 | strcpy(dirent->d_name, nameptr); | ||
605 | |||
606 | out: | ||
607 | return fake_pdu.offset; | ||
608 | } | ||
609 | EXPORT_SYMBOL(p9dirent_read); | ||