More async RPC work.
[bluesky.git] / nfs3 / nfs3.c
index 4b1b8c5..693175b 100644 (file)
@@ -140,13 +140,13 @@ void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode)
 }
 
 void *
-nfsproc3_null_3_svc(void *argp, struct svc_req *rqstp)
+nfsproc3_null_3_svc(void *argp, RPCRequest *req)
 {
     return null_result;
 }
 
 getattr3res *
-nfsproc3_getattr_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
+nfsproc3_getattr_3_svc(nfs_fh3 *argp, RPCRequest *req)
 {
     static getattr3res result;
 
@@ -162,7 +162,7 @@ nfsproc3_getattr_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
 }
 
 wccstat3 *
-nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
+nfsproc3_setattr_3_svc(setattr3args *argp, RPCRequest *req)
 {
     static wccstat3 result;
 
@@ -195,7 +195,7 @@ nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
 }
 
 lookup3res *
-nfsproc3_lookup_3_svc(diropargs3 *argp, struct svc_req *rqstp)
+nfsproc3_lookup_3_svc(diropargs3 *argp, RPCRequest *req)
 {
     static lookup3res result;
 
@@ -243,7 +243,7 @@ nfsproc3_lookup_3_svc(diropargs3 *argp, struct svc_req *rqstp)
 }
 
 access3res *
-nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp)
+nfsproc3_access_3_svc(access3args *argp, RPCRequest *req)
 {
     static access3res result;
 
@@ -263,7 +263,7 @@ nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp)
 }
 
 readlink3res *
-nfsproc3_readlink_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
+nfsproc3_readlink_3_svc(nfs_fh3 *argp, RPCRequest *req)
 {
     static readlink3res result;
     memset(&result, 0, sizeof(result));
@@ -288,7 +288,7 @@ nfsproc3_readlink_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
 }
 
 read3res *
-nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
+nfsproc3_read_3_svc(read3args *argp, RPCRequest *req)
 {
     static read3res result;
     static char buf[32768];
@@ -325,7 +325,7 @@ nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
 }
 
 write3res *
-nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
+nfsproc3_write_3_svc(write3args *argp, RPCRequest *req)
 {
     static write3res result;
     struct wcc_data wcc;
@@ -367,7 +367,7 @@ nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
 }
 
 diropres3 *
-nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
+nfsproc3_create_3_svc(create3args *argp, RPCRequest *req)
 {
     static diropres3 result;
     struct wcc_data wcc;
@@ -428,7 +428,7 @@ nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
 }
 
 diropres3 *
-nfsproc3_mkdir_3_svc(mkdir3args *argp, struct svc_req *rqstp)
+nfsproc3_mkdir_3_svc(mkdir3args *argp, RPCRequest *req)
 {
     static diropres3 result;
     struct wcc_data wcc;
@@ -489,7 +489,7 @@ nfsproc3_mkdir_3_svc(mkdir3args *argp, struct svc_req *rqstp)
 }
 
 diropres3 *
-nfsproc3_symlink_3_svc(symlink3args *argp, struct svc_req *rqstp)
+nfsproc3_symlink_3_svc(symlink3args *argp, RPCRequest *req)
 {
     static diropres3 result;
     struct wcc_data wcc;
@@ -550,7 +550,7 @@ nfsproc3_symlink_3_svc(symlink3args *argp, struct svc_req *rqstp)
 }
 
 diropres3 *
-nfsproc3_mknod_3_svc(mknod3args *argp, struct svc_req *rqstp)
+nfsproc3_mknod_3_svc(mknod3args *argp, RPCRequest *req)
 {
     static diropres3 result;
 
@@ -560,7 +560,7 @@ nfsproc3_mknod_3_svc(mknod3args *argp, struct svc_req *rqstp)
 }
 
 wccstat3 *
-nfsproc3_remove_3_svc(diropargs3 *argp, struct svc_req *rqstp)
+nfsproc3_remove_3_svc(diropargs3 *argp, RPCRequest *req)
 {
     static wccstat3 result;
 
@@ -596,7 +596,7 @@ nfsproc3_remove_3_svc(diropargs3 *argp, struct svc_req *rqstp)
 }
 
 wccstat3 *
-nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
+nfsproc3_rmdir_3_svc(diropargs3 *argp, RPCRequest *req)
 {
     static wccstat3 result;
 
@@ -650,7 +650,7 @@ nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
 }
 
 rename3res *
-nfsproc3_rename_3_svc(rename3args *argp, struct svc_req *rqstp)
+nfsproc3_rename_3_svc(rename3args *argp, RPCRequest *req)
 {
     static rename3res result;
     wcc_data *wcc1 = &result.rename3res_u.res.fromdir_wcc;
@@ -689,7 +689,7 @@ nfsproc3_rename_3_svc(rename3args *argp, struct svc_req *rqstp)
 }
 
 link3res *
-nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp)
+nfsproc3_link_3_svc(link3args *argp, RPCRequest *req)
 {
     static link3res result;
     struct wcc_data wcc;
@@ -747,9 +747,9 @@ nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp)
 gint bluesky_dirent_compare(gconstpointer a, gconstpointer b,
                             gpointer unused);
 
-#define MAX_READDIR_DIRENTS 4
+#define MAX_READDIR_DIRENTS 64
 readdir3res *
-nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
+nfsproc3_readdir_3_svc(readdir3args *argp, RPCRequest *req)
 {
     static readdir3res result;
 
@@ -795,8 +795,15 @@ nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
 }
 
 readdirplus3res *
-nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
+nfsproc3_readdirplus_3_svc(readdirplus3args *argp, RPCRequest *req)
 {
+    /* XDR-encoded sizes:
+     *   post_op_attr: 88 bytes
+     *   base readdirplus3resok: 88 + 16 bytes
+     *   base directory entry: 24 bytes + filename
+     *   attributes/fh3: 88 + 8 + filehandle size
+     */
+    size_t dircount = 88 + 16, attrcount = 0;
     static readdirplus3res result;
 
     BlueSkyInode *dir = lookup_fh(&argp->dir);
@@ -826,6 +833,11 @@ nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
         BlueSkyDirent *d = g_sequence_get(i);
         BlueSkyInode *inode = bluesky_get_inode(fs, d->inum);
         if (inode != NULL) {
+            dircount += 24 + ((strlen(d->name) + 3) & ~3);
+            attrcount += 88 + 8 + 8;
+            if (dircount > argp->dircount
+                || dircount + attrcount > argp->maxcount)
+                break;
             dirents[count].fileid = d->inum;
             dirents[count].name = d->name;
             dirents[count].cookie = d->cookie;
@@ -854,17 +866,34 @@ nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
 }
 
 fsstat3res *
-nfsproc3_fsstat_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
+nfsproc3_fsstat_3_svc(nfs_fh3 *argp, RPCRequest *req)
 {
     static fsstat3res result;
 
-    result.status = NFS3ERR_NOTSUPP;
+    BlueSkyInode *inode = lookup_fh(argp);
+    if (inode == NULL) {
+        result.status = NFS3ERR_STALE;
+        result.fsstat3res_u.resfail.present = FALSE;
+        return &result;
+    }
+
+    result.status = NFS3_OK;
+    result.fsstat3res_u.resok.obj_attributes.present = TRUE;
+    encode_fattr3(&result.fsstat3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
+
+    result.fsstat3res_u.resok.tbytes = (1 << 30);
+    result.fsstat3res_u.resok.fbytes = (1 << 30);
+    result.fsstat3res_u.resok.abytes = (1 << 30);
+    result.fsstat3res_u.resok.tfiles = 0;
+    result.fsstat3res_u.resok.ffiles = 0;
+    result.fsstat3res_u.resok.afiles = 0;
+    result.fsstat3res_u.resok.invarsec = 0;
 
     return &result;
 }
 
 fsinfo3res *
-nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
+nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, RPCRequest *req)
 {
     static fsinfo3res result;
 
@@ -889,7 +918,7 @@ nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
 }
 
 pathconf3res *
-nfsproc3_pathconf_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
+nfsproc3_pathconf_3_svc(nfs_fh3 *argp, RPCRequest *req)
 {
     static pathconf3res result;
 
@@ -908,7 +937,7 @@ nfsproc3_pathconf_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
 }
 
 commit3res *
-nfsproc3_commit_3_svc(commit3args *argp, struct svc_req *rqstp)
+nfsproc3_commit_3_svc(commit3args *argp, RPCRequest *req)
 {
     static commit3res result;