From: Michael Vrable Date: Wed, 13 Jan 2010 19:53:01 +0000 (-0800) Subject: Remove most static variables in the NFS server functions. X-Git-Url: http://git.vrable.net/?p=bluesky.git;a=commitdiff_plain;h=53817147ff42b54d2b103216983cbf3e1ffa341f Remove most static variables in the NFS server functions. --- diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index ce8c27e..3f858ac 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -9,9 +9,6 @@ extern BlueSkyFS *fs; -static int null_int; -static void *null_result = (void *)&null_int; - /* Check that a string is a valid file name. We require that it be valid * UTF-8, that it not be empty, and that it not contain embedded forward * slashes. Also checks that the length of the string is not more than the @@ -141,12 +138,13 @@ void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode) void nfsproc3_null_3_svc(void *argp, RPCRequest *req) { - async_rpc_send_reply(req, null_result); + async_rpc_send_reply(req, NULL); } void nfsproc3_getattr_3_svc(nfs_fh3 *argp, RPCRequest *req) { - static getattr3res result; + getattr3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *inode = lookup_fh(argp); if (inode != NULL) { @@ -161,7 +159,8 @@ void nfsproc3_getattr_3_svc(nfs_fh3 *argp, RPCRequest *req) void nfsproc3_setattr_3_svc(setattr3args *argp, RPCRequest *req) { - static wccstat3 result; + wccstat3 result; + memset(&result, 0, sizeof(result)); result.wccstat3_u.wcc.before.present = FALSE; result.wccstat3_u.wcc.after.present = FALSE; @@ -195,7 +194,8 @@ void nfsproc3_setattr_3_svc(setattr3args *argp, RPCRequest *req) void nfsproc3_lookup_3_svc(diropargs3 *argp, RPCRequest *req) { - static lookup3res result; + lookup3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *dir = lookup_fh(&argp->dir); if (dir == NULL) { @@ -236,7 +236,7 @@ void nfsproc3_lookup_3_svc(diropargs3 *argp, RPCRequest *req) result.lookup3res_u.resok.obj_attributes.present = TRUE; encode_fattr3(&result.lookup3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode); - static uint64_t fh_bytes; + uint64_t fh_bytes; fh_bytes = GUINT64_TO_BE(inum); result.lookup3res_u.resok.object.data.data_len = 8; result.lookup3res_u.resok.object.data.data_val = (char *)&fh_bytes; @@ -246,7 +246,8 @@ void nfsproc3_lookup_3_svc(diropargs3 *argp, RPCRequest *req) void nfsproc3_access_3_svc(access3args *argp, RPCRequest *req) { - static access3res result; + access3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *inode = lookup_fh(&argp->object); if (inode == NULL) { @@ -266,7 +267,7 @@ void nfsproc3_access_3_svc(access3args *argp, RPCRequest *req) void nfsproc3_readlink_3_svc(nfs_fh3 *argp, RPCRequest *req) { - static readlink3res result; + readlink3res result; memset(&result, 0, sizeof(result)); BlueSkyInode *inode = lookup_fh(argp); @@ -290,8 +291,9 @@ void nfsproc3_readlink_3_svc(nfs_fh3 *argp, RPCRequest *req) void nfsproc3_read_3_svc(read3args *argp, RPCRequest *req) { - static read3res result; - static char buf[32768]; + read3res result; + memset(&result, 0, sizeof(result)); + char buf[32768]; BlueSkyInode *inode = lookup_fh(&argp->file); if (inode == NULL) { @@ -327,7 +329,8 @@ void nfsproc3_read_3_svc(read3args *argp, RPCRequest *req) void nfsproc3_write_3_svc(write3args *argp, RPCRequest *req) { - static write3res result; + write3res result; + memset(&result, 0, sizeof(result)); struct wcc_data wcc; memset(&wcc, 0, sizeof(wcc)); @@ -370,7 +373,8 @@ void nfsproc3_write_3_svc(write3args *argp, RPCRequest *req) void nfsproc3_create_3_svc(create3args *argp, RPCRequest *req) { - static diropres3 result; + diropres3 result; + memset(&result, 0, sizeof(result)); struct wcc_data wcc; memset(&wcc, 0, sizeof(wcc)); @@ -422,7 +426,7 @@ void nfsproc3_create_3_svc(create3args *argp, RPCRequest *req) encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file); result.diropres3_u.resok.dir_wcc = wcc; - static uint64_t fh_bytes; + uint64_t fh_bytes; fh_bytes = GUINT64_TO_BE(file->inum); result.diropres3_u.resok.obj.present = TRUE; result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8; @@ -433,7 +437,8 @@ void nfsproc3_create_3_svc(create3args *argp, RPCRequest *req) void nfsproc3_mkdir_3_svc(mkdir3args *argp, RPCRequest *req) { - static diropres3 result; + diropres3 result; + memset(&result, 0, sizeof(result)); struct wcc_data wcc; memset(&wcc, 0, sizeof(wcc)); @@ -485,7 +490,7 @@ void nfsproc3_mkdir_3_svc(mkdir3args *argp, RPCRequest *req) encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file); result.diropres3_u.resok.dir_wcc = wcc; - static uint64_t fh_bytes; + uint64_t fh_bytes; fh_bytes = GUINT64_TO_BE(file->inum); result.diropres3_u.resok.obj.present = TRUE; result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8; @@ -496,7 +501,8 @@ void nfsproc3_mkdir_3_svc(mkdir3args *argp, RPCRequest *req) void nfsproc3_symlink_3_svc(symlink3args *argp, RPCRequest *req) { - static diropres3 result; + diropres3 result; + memset(&result, 0, sizeof(result)); struct wcc_data wcc; memset(&wcc, 0, sizeof(wcc)); @@ -548,7 +554,7 @@ void nfsproc3_symlink_3_svc(symlink3args *argp, RPCRequest *req) encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file); result.diropres3_u.resok.dir_wcc = wcc; - static uint64_t fh_bytes; + uint64_t fh_bytes; fh_bytes = GUINT64_TO_BE(file->inum); result.diropres3_u.resok.obj.present = TRUE; result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8; @@ -559,7 +565,8 @@ void nfsproc3_symlink_3_svc(symlink3args *argp, RPCRequest *req) void nfsproc3_mknod_3_svc(mknod3args *argp, RPCRequest *req) { - static diropres3 result; + diropres3 result; + memset(&result, 0, sizeof(result)); result.status = NFS3ERR_NOTSUPP; @@ -568,10 +575,8 @@ void nfsproc3_mknod_3_svc(mknod3args *argp, RPCRequest *req) void nfsproc3_remove_3_svc(diropargs3 *argp, RPCRequest *req) { - static wccstat3 result; - - result.wccstat3_u.wcc.before.present = FALSE; - result.wccstat3_u.wcc.after.present = FALSE; + wccstat3 result; + memset(&result, 0, sizeof(result)); BlueSkyInode *dir = lookup_fh(&argp->dir); if (dir == NULL) { @@ -605,10 +610,8 @@ void nfsproc3_remove_3_svc(diropargs3 *argp, RPCRequest *req) void nfsproc3_rmdir_3_svc(diropargs3 *argp, RPCRequest *req) { - static wccstat3 result; - - result.wccstat3_u.wcc.before.present = FALSE; - result.wccstat3_u.wcc.after.present = FALSE; + wccstat3 result; + memset(&result, 0, sizeof(result)); BlueSkyInode *dir = lookup_fh(&argp->dir); if (dir == NULL) { @@ -663,11 +666,10 @@ void nfsproc3_rmdir_3_svc(diropargs3 *argp, RPCRequest *req) void nfsproc3_rename_3_svc(rename3args *argp, RPCRequest *req) { - static rename3res result; + rename3res result; + memset(&result, 0, sizeof(result)); wcc_data *wcc1 = &result.rename3res_u.res.fromdir_wcc; wcc_data *wcc2 = &result.rename3res_u.res.todir_wcc; - memset(wcc1, 0, sizeof(*wcc1)); - memset(wcc2, 0, sizeof(*wcc2)); BlueSkyInode *dir1 = lookup_fh(&argp->from.dir); if (dir1 == NULL) { @@ -703,7 +705,8 @@ void nfsproc3_rename_3_svc(rename3args *argp, RPCRequest *req) void nfsproc3_link_3_svc(link3args *argp, RPCRequest *req) { - static link3res result; + link3res result; + memset(&result, 0, sizeof(result)); struct wcc_data wcc; memset(&wcc, 0, sizeof(wcc)); @@ -767,7 +770,8 @@ gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, #define MAX_READDIR_DIRENTS 64 void nfsproc3_readdir_3_svc(readdir3args *argp, RPCRequest *req) { - static readdir3res result; + readdir3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *dir = lookup_fh(&argp->dir); if (dir == NULL) { @@ -783,7 +787,7 @@ void nfsproc3_readdir_3_svc(readdir3args *argp, RPCRequest *req) memset(result.readdir3res_u.resok.cookieverf, 0, sizeof(result.readdir3res_u.resok.cookieverf)); - static entry3 dirents[MAX_READDIR_DIRENTS]; + entry3 dirents[MAX_READDIR_DIRENTS]; int count = 0; BlueSkyDirent start = {NULL, NULL, argp->cookie, 0}; @@ -820,7 +824,8 @@ void nfsproc3_readdirplus_3_svc(readdirplus3args *argp, RPCRequest *req) * attributes/fh3: 88 + 8 + filehandle size */ size_t dircount = 88 + 16, attrcount = 0; - static readdirplus3res result; + readdirplus3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *dir = lookup_fh(&argp->dir); if (dir == NULL) { @@ -836,8 +841,8 @@ void nfsproc3_readdirplus_3_svc(readdirplus3args *argp, RPCRequest *req) memset(result.readdirplus3res_u.resok.cookieverf, 0, sizeof(result.readdirplus3res_u.resok.cookieverf)); - static entryplus3 dirents[MAX_READDIR_DIRENTS]; - static uint64_t fh_bytes[MAX_READDIR_DIRENTS]; + entryplus3 dirents[MAX_READDIR_DIRENTS]; + uint64_t fh_bytes[MAX_READDIR_DIRENTS]; int count = 0; /* TODO: Handle dircount, maxcount arguments from client. */ @@ -884,7 +889,8 @@ void nfsproc3_readdirplus_3_svc(readdirplus3args *argp, RPCRequest *req) void nfsproc3_fsstat_3_svc(nfs_fh3 *argp, RPCRequest *req) { - static fsstat3res result; + fsstat3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *inode = lookup_fh(argp); if (inode == NULL) { @@ -911,7 +917,8 @@ void nfsproc3_fsstat_3_svc(nfs_fh3 *argp, RPCRequest *req) void nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, RPCRequest *req) { - static fsinfo3res result; + fsinfo3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *inode = bluesky_get_inode(fs, 1); result.status = NFS3_OK; @@ -935,7 +942,8 @@ void nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, RPCRequest *req) void nfsproc3_pathconf_3_svc(nfs_fh3 *argp, RPCRequest *req) { - static pathconf3res result; + pathconf3res result; + memset(&result, 0, sizeof(result)); BlueSkyInode *inode = bluesky_get_inode(fs, 1); result.status = NFS3_OK; @@ -953,7 +961,8 @@ void nfsproc3_pathconf_3_svc(nfs_fh3 *argp, RPCRequest *req) void nfsproc3_commit_3_svc(commit3args *argp, RPCRequest *req) { - static commit3res result; + commit3res result; + memset(&result, 0, sizeof(result)); result.status = NFS3ERR_NOTSUPP; diff --git a/nfs3/rpc.c b/nfs3/rpc.c index deabbc1..67a9c7c 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -161,7 +161,7 @@ async_rpc_send_reply(RPCRequest *req, void *result) static char reply_buf[MAX_RPC_MSGSIZE]; XDR xdr_out; xdrmem_create(&xdr_out, reply_buf, MAX_RPC_MSGSIZE, XDR_ENCODE); - if (result != NULL && !req->xdr_result(&xdr_out, result)) { + if (!req->xdr_result(&xdr_out, result)) { async_rpc_send_failure(req, SYSTEM_ERR); return; }