Skip to content

Commit 1beef14

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
lockd: Update the NLMv4 TEST results encoder to use struct xdr_stream
Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent ec757e4 commit 1beef14

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

fs/lockd/xdr4.c

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include "svcxdr.h"
2222

23-
#define NLMDBG_FACILITY NLMDBG_XDR
24-
2523
static inline loff_t
2624
s64_to_loff_t(__s64 offset)
2725
{
@@ -110,44 +108,44 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
110108
return true;
111109
}
112110

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)
118113
{
119-
s64 start, len;
114+
const struct file_lock *fl = &lock->fl;
115+
s64 start, len;
120116

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+
}
125136

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;
147146
}
148147

149-
dprintk("xdr: after encode_testres (p %p resp %p)\n", p, resp);
150-
return p;
148+
return true;
151149
}
152150

153151

@@ -338,11 +336,11 @@ nlm4svc_encode_void(struct svc_rqst *rqstp, __be32 *p)
338336
int
339337
nlm4svc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
340338
{
339+
struct xdr_stream *xdr = &rqstp->rq_res_stream;
341340
struct nlm_res *resp = rqstp->rq_resp;
342341

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);
346344
}
347345

348346
int

0 commit comments

Comments
 (0)