X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=nfs3%2Fnfs3.c;h=693175be4b754cfb71b46671895ae8ac5e263948;hb=c3245fe423dd5c3a68b4c1e90ba253e7fae3473e;hp=0ba7f56a4cb3757504d60e72fb0c04e9959bfef7;hpb=4bef26446b9100f63ac3c953b7f96f1966673980;p=bluesky.git diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index 0ba7f56..693175b 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -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,17 +596,61 @@ 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; - result.status = NFS3ERR_NOTSUPP; + result.wccstat3_u.wcc.before.present = FALSE; + result.wccstat3_u.wcc.after.present = FALSE; + + BlueSkyInode *dir = lookup_fh(&argp->dir); + if (dir == NULL) { + result.status = NFS3ERR_STALE; + return &result; + } + + encode_pre_wcc(&result.wccstat3_u.wcc, dir); + + if (!validate_filename(argp->name) + || strcmp(argp->name, ".") == 0 + || strcmp(argp->name, "..") == 0) + { + result.status = NFS3ERR_NOENT; + return &result; + } + + uint64_t inum = bluesky_directory_lookup(dir, argp->name); + BlueSkyInode *inode = bluesky_get_inode(fs, inum); + if (inode == NULL) { + result.status = NFS3ERR_NOENT; + return &result; + } + + if (inode->type != BLUESKY_DIRECTORY) { + result.status = NFS3ERR_NOTDIR; + return &result; + } + if (g_sequence_get_length(inode->dirents) > 0) { + printf("Directory not empty: %d entries\n", + g_sequence_get_length(inode->dirents)); + result.status = NFS3ERR_NOTEMPTY; + return &result; + } + + /* TODO: Decrement link count, deallocate inode if needed. */ + + bluesky_directory_remove(dir, argp->name); + + result.status = NFS3_OK; + result.wccstat3_u.wcc.after.present = TRUE; + encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes, + dir); return &result; } 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; @@ -645,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; @@ -703,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; @@ -751,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); @@ -782,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; @@ -810,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; @@ -845,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; @@ -864,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;