Implement flushing of file blocks to Amazon S3.
[bluesky.git] / nfs3 / nfs3.c
index 04a77b6..051d728 100644 (file)
@@ -188,8 +188,35 @@ read3res *
 nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
 {
     static read3res result;
+    static char buf[32768];
 
-    result.status = NFS3ERR_NOTSUPP;
+    BlueSkyInode *inode = lookup_fh(&argp->file);
+    if (inode == NULL) {
+        result.status = NFS3ERR_STALE;
+        result.read3res_u.resfail.present = FALSE;
+        return &result;
+    }
+
+    int count = argp->count;
+    if (argp->offset >= inode->size) {
+        count = 0;
+        result.read3res_u.resok.eof = TRUE;
+    } else {
+        count = MIN(count, inode->size - argp->offset);
+        if (argp->offset + count == inode->size)
+            result.read3res_u.resok.eof = TRUE;
+        else
+            result.read3res_u.resok.eof = FALSE;
+
+        bluesky_file_read(inode, argp->offset, buf, count);
+    }
+
+    result.status = NFS3_OK;
+    result.read3res_u.resok.file_attributes.present = TRUE;
+    encode_fattr3(&result.read3res_u.resok.file_attributes.post_op_attr_u.attributes, inode);
+    result.read3res_u.resok.count = count;
+    result.read3res_u.resok.data.data_val = buf;
+    result.read3res_u.resok.data.data_len = count;
 
     return &result;
 }
@@ -219,7 +246,13 @@ nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
     if (lastbyte > inode->size) {
         bluesky_file_truncate(inode, lastbyte);
     }
-    inode->change_count++;
+
+    if (argp->data.data_len < argp->count) {
+        /* ??? */
+    } else {
+        bluesky_file_write(inode, argp->offset,
+                           argp->data.data_val, argp->count);
+    }
 
     encode_fattr3(&wcc.after.post_op_attr_u.attributes, inode);
     result.write3res_u.resok.file_wcc = wcc;
@@ -260,7 +293,7 @@ nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
     }
 
     BlueSkyInode *file;
-    file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), BLUESKY_REGULAR);
+    file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_REGULAR);
     file->nlink = 1;
     file->mode = 0755;
     int64_t time = bluesky_get_current_time();