Skip to content

Commit fbd5573

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: prepare delegation code for handing out *_ATTRS_DELEG delegations
Add some preparatory code to various functions that handle delegation types to allow them to handle the OPEN_DELEGATE_*_ATTRS_DELEG constants. Add helpers for detecting whether it's a read or write deleg, and whether the attributes are delegated. Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent c9c99a3 commit fbd5573

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

fs/nfsd/nfs4state.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,6 +2951,21 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
29512951
return 0;
29522952
}
29532953

2954+
static char *nfs4_show_deleg_type(u32 dl_type)
2955+
{
2956+
switch (dl_type) {
2957+
case OPEN_DELEGATE_READ:
2958+
return "r";
2959+
case OPEN_DELEGATE_WRITE:
2960+
return "w";
2961+
case OPEN_DELEGATE_READ_ATTRS_DELEG:
2962+
return "ra";
2963+
case OPEN_DELEGATE_WRITE_ATTRS_DELEG:
2964+
return "wa";
2965+
}
2966+
return "?";
2967+
}
2968+
29542969
static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
29552970
{
29562971
struct nfs4_delegation *ds;
@@ -2964,8 +2979,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
29642979
nfs4_show_stateid(s, &st->sc_stateid);
29652980
seq_puts(s, ": { type: deleg, ");
29662981

2967-
seq_printf(s, "access: %s",
2968-
ds->dl_type == OPEN_DELEGATE_READ ? "r" : "w");
2982+
seq_printf(s, "access: %s", nfs4_show_deleg_type(ds->dl_type));
29692983

29702984
/* XXX: lease time, whether it's being recalled. */
29712985

@@ -5581,7 +5595,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
55815595
static inline __be32
55825596
nfs4_check_delegmode(struct nfs4_delegation *dp, int flags)
55835597
{
5584-
if ((flags & WR_STATE) && (dp->dl_type == OPEN_DELEGATE_READ))
5598+
if ((flags & WR_STATE) && deleg_is_read(dp->dl_type))
55855599
return nfserr_openmode;
55865600
else
55875601
return nfs_ok;
@@ -5813,8 +5827,7 @@ static bool nfsd4_cb_channel_good(struct nfs4_client *clp)
58135827
return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN;
58145828
}
58155829

5816-
static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp,
5817-
int flag)
5830+
static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp)
58185831
{
58195832
struct file_lease *fl;
58205833

@@ -5823,7 +5836,7 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp,
58235836
return NULL;
58245837
fl->fl_lmops = &nfsd_lease_mng_ops;
58255838
fl->c.flc_flags = FL_DELEG;
5826-
fl->c.flc_type = flag == OPEN_DELEGATE_READ ? F_RDLCK : F_WRLCK;
5839+
fl->c.flc_type = deleg_is_read(dp->dl_type) ? F_RDLCK : F_WRLCK;
58275840
fl->c.flc_owner = (fl_owner_t)dp;
58285841
fl->c.flc_pid = current->tgid;
58295842
fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file;
@@ -6010,7 +6023,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
60106023
if (!dp)
60116024
goto out_delegees;
60126025

6013-
fl = nfs4_alloc_init_lease(dp, dl_type);
6026+
fl = nfs4_alloc_init_lease(dp);
60146027
if (!fl)
60156028
goto out_clnt_odstate;
60166029

@@ -6210,14 +6223,14 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp,
62106223
static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open,
62116224
struct nfs4_delegation *dp)
62126225
{
6213-
if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_READ_DELEG &&
6214-
dp->dl_type == OPEN_DELEGATE_WRITE) {
6215-
open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
6216-
open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE;
6217-
} else if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG &&
6218-
dp->dl_type == OPEN_DELEGATE_WRITE) {
6219-
open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
6220-
open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE;
6226+
if (deleg_is_write(dp->dl_type)) {
6227+
if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_READ_DELEG) {
6228+
open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
6229+
open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE;
6230+
} else if (open->op_deleg_want == OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG) {
6231+
open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
6232+
open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE;
6233+
}
62216234
}
62226235
/* Otherwise the client must be confused wanting a delegation
62236236
* it already has, therefore we don't return

fs/nfsd/nfs4xdr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,10 +4237,12 @@ nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open)
42374237
status = nfs_ok;
42384238
break;
42394239
case OPEN_DELEGATE_READ:
4240+
case OPEN_DELEGATE_READ_ATTRS_DELEG:
42404241
/* read */
42414242
status = nfsd4_encode_open_read_delegation4(xdr, open);
42424243
break;
42434244
case OPEN_DELEGATE_WRITE:
4245+
case OPEN_DELEGATE_WRITE_ATTRS_DELEG:
42444246
/* write */
42454247
status = nfsd4_encode_open_write_delegation4(xdr, open);
42464248
break;

fs/nfsd/state.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ struct nfs4_delegation {
207207
struct nfs4_cb_fattr dl_cb_fattr;
208208
};
209209

210+
static inline bool deleg_is_read(u32 dl_type)
211+
{
212+
return (dl_type == OPEN_DELEGATE_READ || dl_type == OPEN_DELEGATE_READ_ATTRS_DELEG);
213+
}
214+
215+
static inline bool deleg_is_write(u32 dl_type)
216+
{
217+
return (dl_type == OPEN_DELEGATE_WRITE || dl_type == OPEN_DELEGATE_WRITE_ATTRS_DELEG);
218+
}
219+
220+
static inline bool deleg_attrs_deleg(u32 dl_type)
221+
{
222+
return dl_type == OPEN_DELEGATE_READ_ATTRS_DELEG ||
223+
dl_type == OPEN_DELEGATE_WRITE_ATTRS_DELEG;
224+
}
225+
210226
#define cb_to_delegation(cb) \
211227
container_of(cb, struct nfs4_delegation, dl_recall)
212228

0 commit comments

Comments
 (0)