aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2010-12-14 09:58:40 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-16 12:37:25 -0500
commit98eb2b4f9323bcf2a46476576d3155758cb0a473 (patch)
tree7b7308f76ec761249ba1992a7106633d00035384
parent49b170047f4a9fe1483132e14a11bdf493bdb8af (diff)
NFS: Avoid return code checking in mount XDR encoder functions
Clean up. The trend in the other XDR encoder functions is to BUG() when encoding problems occur, since a problem here is always due to a local coding error. Then, instead of a status, zero is unconditionally returned. Update the mount client XDR encoders to behave this way. To finish the update, use the new-style be32_to_cpup() and cpu_to_be32() macros, and compute the buffer sizes using raw integers instead of sizeof(). This matches the conventions used in other XDR functions. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Tested-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--fs/nfs/mount_clnt.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index 4f981f1f6689..c82547e49ba1 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -280,20 +280,14 @@ out_call_err:
280 * XDR encode/decode functions for MOUNT 280 * XDR encode/decode functions for MOUNT
281 */ 281 */
282 282
283static int encode_mntdirpath(struct xdr_stream *xdr, const char *pathname) 283static void encode_mntdirpath(struct xdr_stream *xdr, const char *pathname)
284{ 284{
285 const u32 pathname_len = strlen(pathname); 285 const u32 pathname_len = strlen(pathname);
286 __be32 *p; 286 __be32 *p;
287 287
288 if (unlikely(pathname_len > MNTPATHLEN)) 288 BUG_ON(pathname_len > MNTPATHLEN);
289 return -EIO; 289 p = xdr_reserve_space(xdr, 4 + pathname_len);
290
291 p = xdr_reserve_space(xdr, sizeof(u32) + pathname_len);
292 if (unlikely(p == NULL))
293 return -EIO;
294 xdr_encode_opaque(p, pathname, pathname_len); 290 xdr_encode_opaque(p, pathname, pathname_len);
295
296 return 0;
297} 291}
298 292
299static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p, 293static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p,
@@ -302,7 +296,8 @@ static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p,
302 struct xdr_stream xdr; 296 struct xdr_stream xdr;
303 297
304 xdr_init_encode(&xdr, &req->rq_snd_buf, p); 298 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
305 return encode_mntdirpath(&xdr, dirpath); 299 encode_mntdirpath(&xdr, dirpath);
300 return 0;
306} 301}
307 302
308/* 303/*
@@ -320,10 +315,10 @@ static int decode_status(struct xdr_stream *xdr, struct mountres *res)
320 u32 status; 315 u32 status;
321 __be32 *p; 316 __be32 *p;
322 317
323 p = xdr_inline_decode(xdr, sizeof(status)); 318 p = xdr_inline_decode(xdr, 4);
324 if (unlikely(p == NULL)) 319 if (unlikely(p == NULL))
325 return -EIO; 320 return -EIO;
326 status = ntohl(*p); 321 status = be32_to_cpup(p);
327 322
328 for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) { 323 for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) {
329 if (mnt_errtbl[i].status == status) { 324 if (mnt_errtbl[i].status == status) {
@@ -371,10 +366,10 @@ static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res)
371 u32 status; 366 u32 status;
372 __be32 *p; 367 __be32 *p;
373 368
374 p = xdr_inline_decode(xdr, sizeof(status)); 369 p = xdr_inline_decode(xdr, 4);
375 if (unlikely(p == NULL)) 370 if (unlikely(p == NULL))
376 return -EIO; 371 return -EIO;
377 status = ntohl(*p); 372 status = be32_to_cpup(p);
378 373
379 for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) { 374 for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) {
380 if (mnt3_errtbl[i].status == status) { 375 if (mnt3_errtbl[i].status == status) {
@@ -394,11 +389,11 @@ static int decode_fhandle3(struct xdr_stream *xdr, struct mountres *res)
394 u32 size; 389 u32 size;
395 __be32 *p; 390 __be32 *p;
396 391
397 p = xdr_inline_decode(xdr, sizeof(size)); 392 p = xdr_inline_decode(xdr, 4);
398 if (unlikely(p == NULL)) 393 if (unlikely(p == NULL))
399 return -EIO; 394 return -EIO;
400 395
401 size = ntohl(*p++); 396 size = be32_to_cpup(p);
402 if (size > NFS3_FHSIZE || size == 0) 397 if (size > NFS3_FHSIZE || size == 0)
403 return -EIO; 398 return -EIO;
404 399
@@ -421,15 +416,15 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)
421 if (*count == 0) 416 if (*count == 0)
422 return 0; 417 return 0;
423 418
424 p = xdr_inline_decode(xdr, sizeof(entries)); 419 p = xdr_inline_decode(xdr, 4);
425 if (unlikely(p == NULL)) 420 if (unlikely(p == NULL))
426 return -EIO; 421 return -EIO;
427 entries = ntohl(*p); 422 entries = be32_to_cpup(p);
428 dprintk("NFS: received %u auth flavors\n", entries); 423 dprintk("NFS: received %u auth flavors\n", entries);
429 if (entries > NFS_MAX_SECFLAVORS) 424 if (entries > NFS_MAX_SECFLAVORS)
430 entries = NFS_MAX_SECFLAVORS; 425 entries = NFS_MAX_SECFLAVORS;
431 426
432 p = xdr_inline_decode(xdr, sizeof(u32) * entries); 427 p = xdr_inline_decode(xdr, 4 * entries);
433 if (unlikely(p == NULL)) 428 if (unlikely(p == NULL))
434 return -EIO; 429 return -EIO;
435 430
@@ -437,7 +432,7 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res)
437 entries = *count; 432 entries = *count;
438 433
439 for (i = 0; i < entries; i++) { 434 for (i = 0; i < entries; i++) {
440 flavors[i] = ntohl(*p++); 435 flavors[i] = be32_to_cpup(p++);
441 dprintk("NFS: auth flavor[%u]: %d\n", i, flavors[i]); 436 dprintk("NFS: auth flavor[%u]: %d\n", i, flavors[i]);
442 } 437 }
443 *count = i; 438 *count = i;