|
20 | 20 |
|
21 | 21 | #include "svcxdr.h"
|
22 | 22 |
|
23 |
| -#define NLMDBG_FACILITY NLMDBG_XDR |
24 |
| - |
25 | 23 | static inline loff_t
|
26 | 24 | s64_to_loff_t(__s64 offset)
|
27 | 25 | {
|
@@ -110,44 +108,44 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
|
110 | 108 | return true;
|
111 | 109 | }
|
112 | 110 |
|
113 |
| -/* |
114 |
| - * Encode result of a TEST/TEST_MSG call |
115 |
| - */ |
116 |
| -static __be32 * |
117 |
| -nlm4_encode_testres(__be32 *p, struct nlm_res *resp) |
| 111 | +static bool |
| 112 | +svcxdr_encode_holder(struct xdr_stream *xdr, const struct nlm_lock *lock) |
118 | 113 | {
|
119 |
| - s64 start, len; |
| 114 | + const struct file_lock *fl = &lock->fl; |
| 115 | + s64 start, len; |
120 | 116 |
|
121 |
| - dprintk("xdr: before encode_testres (p %p resp %p)\n", p, resp); |
122 |
| - if (!(p = nlm4_encode_cookie(p, &resp->cookie))) |
123 |
| - return NULL; |
124 |
| - *p++ = resp->status; |
| 117 | + /* exclusive */ |
| 118 | + if (xdr_stream_encode_bool(xdr, fl->fl_type != F_RDLCK) < 0) |
| 119 | + return false; |
| 120 | + if (xdr_stream_encode_u32(xdr, lock->svid) < 0) |
| 121 | + return false; |
| 122 | + if (!svcxdr_encode_owner(xdr, &lock->oh)) |
| 123 | + return false; |
| 124 | + start = loff_t_to_s64(fl->fl_start); |
| 125 | + if (fl->fl_end == OFFSET_MAX) |
| 126 | + len = 0; |
| 127 | + else |
| 128 | + len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1); |
| 129 | + if (xdr_stream_encode_u64(xdr, start) < 0) |
| 130 | + return false; |
| 131 | + if (xdr_stream_encode_u64(xdr, len) < 0) |
| 132 | + return false; |
| 133 | + |
| 134 | + return true; |
| 135 | +} |
125 | 136 |
|
126 |
| - if (resp->status == nlm_lck_denied) { |
127 |
| - struct file_lock *fl = &resp->lock.fl; |
128 |
| - |
129 |
| - *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one; |
130 |
| - *p++ = htonl(resp->lock.svid); |
131 |
| - |
132 |
| - /* Encode owner handle. */ |
133 |
| - if (!(p = xdr_encode_netobj(p, &resp->lock.oh))) |
134 |
| - return NULL; |
135 |
| - |
136 |
| - start = loff_t_to_s64(fl->fl_start); |
137 |
| - if (fl->fl_end == OFFSET_MAX) |
138 |
| - len = 0; |
139 |
| - else |
140 |
| - len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1); |
141 |
| - |
142 |
| - p = xdr_encode_hyper(p, start); |
143 |
| - p = xdr_encode_hyper(p, len); |
144 |
| - dprintk("xdr: encode_testres (status %u pid %d type %d start %Ld end %Ld)\n", |
145 |
| - resp->status, (int)resp->lock.svid, fl->fl_type, |
146 |
| - (long long)fl->fl_start, (long long)fl->fl_end); |
| 137 | +static bool |
| 138 | +svcxdr_encode_testrply(struct xdr_stream *xdr, const struct nlm_res *resp) |
| 139 | +{ |
| 140 | + if (!svcxdr_encode_stats(xdr, resp->status)) |
| 141 | + return false; |
| 142 | + switch (resp->status) { |
| 143 | + case nlm_lck_denied: |
| 144 | + if (!svcxdr_encode_holder(xdr, &resp->lock)) |
| 145 | + return false; |
147 | 146 | }
|
148 | 147 |
|
149 |
| - dprintk("xdr: after encode_testres (p %p resp %p)\n", p, resp); |
150 |
| - return p; |
| 148 | + return true; |
151 | 149 | }
|
152 | 150 |
|
153 | 151 |
|
@@ -338,11 +336,11 @@ nlm4svc_encode_void(struct svc_rqst *rqstp, __be32 *p)
|
338 | 336 | int
|
339 | 337 | nlm4svc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
|
340 | 338 | {
|
| 339 | + struct xdr_stream *xdr = &rqstp->rq_res_stream; |
341 | 340 | struct nlm_res *resp = rqstp->rq_resp;
|
342 | 341 |
|
343 |
| - if (!(p = nlm4_encode_testres(p, resp))) |
344 |
| - return 0; |
345 |
| - return xdr_ressize_check(rqstp, p); |
| 342 | + return svcxdr_encode_cookie(xdr, &resp->cookie) && |
| 343 | + svcxdr_encode_testrply(xdr, resp); |
346 | 344 | }
|
347 | 345 |
|
348 | 346 | int
|
|
0 commit comments