Skip to content

Commit ebd9d2c

Browse files
J. Bruce Fieldschucklever
authored andcommitted
nfsd: reshuffle some code
No change in behavior, I'm just moving some code around to avoid forward references in a following patch. (To do someday: figure out how to split up nfs4state.c. It's big and disorganized.) Signed-off-by: J. Bruce Fields <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent a0ce483 commit ebd9d2c

File tree

1 file changed

+118
-117
lines changed

1 file changed

+118
-117
lines changed

fs/nfsd/nfs4state.c

Lines changed: 118 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,124 @@ static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops = {
354354
.release = nfsd4_cb_notify_lock_release,
355355
};
356356

357+
/*
358+
* We store the NONE, READ, WRITE, and BOTH bits separately in the
359+
* st_{access,deny}_bmap field of the stateid, in order to track not
360+
* only what share bits are currently in force, but also what
361+
* combinations of share bits previous opens have used. This allows us
362+
* to enforce the recommendation of rfc 3530 14.2.19 that the server
363+
* return an error if the client attempt to downgrade to a combination
364+
* of share bits not explicable by closing some of its previous opens.
365+
*
366+
* XXX: This enforcement is actually incomplete, since we don't keep
367+
* track of access/deny bit combinations; so, e.g., we allow:
368+
*
369+
* OPEN allow read, deny write
370+
* OPEN allow both, deny none
371+
* DOWNGRADE allow read, deny none
372+
*
373+
* which we should reject.
374+
*/
375+
static unsigned int
376+
bmap_to_share_mode(unsigned long bmap)
377+
{
378+
int i;
379+
unsigned int access = 0;
380+
381+
for (i = 1; i < 4; i++) {
382+
if (test_bit(i, &bmap))
383+
access |= i;
384+
}
385+
return access;
386+
}
387+
388+
/* set share access for a given stateid */
389+
static inline void
390+
set_access(u32 access, struct nfs4_ol_stateid *stp)
391+
{
392+
unsigned char mask = 1 << access;
393+
394+
WARN_ON_ONCE(access > NFS4_SHARE_ACCESS_BOTH);
395+
stp->st_access_bmap |= mask;
396+
}
397+
398+
/* clear share access for a given stateid */
399+
static inline void
400+
clear_access(u32 access, struct nfs4_ol_stateid *stp)
401+
{
402+
unsigned char mask = 1 << access;
403+
404+
WARN_ON_ONCE(access > NFS4_SHARE_ACCESS_BOTH);
405+
stp->st_access_bmap &= ~mask;
406+
}
407+
408+
/* test whether a given stateid has access */
409+
static inline bool
410+
test_access(u32 access, struct nfs4_ol_stateid *stp)
411+
{
412+
unsigned char mask = 1 << access;
413+
414+
return (bool)(stp->st_access_bmap & mask);
415+
}
416+
417+
/* set share deny for a given stateid */
418+
static inline void
419+
set_deny(u32 deny, struct nfs4_ol_stateid *stp)
420+
{
421+
unsigned char mask = 1 << deny;
422+
423+
WARN_ON_ONCE(deny > NFS4_SHARE_DENY_BOTH);
424+
stp->st_deny_bmap |= mask;
425+
}
426+
427+
/* clear share deny for a given stateid */
428+
static inline void
429+
clear_deny(u32 deny, struct nfs4_ol_stateid *stp)
430+
{
431+
unsigned char mask = 1 << deny;
432+
433+
WARN_ON_ONCE(deny > NFS4_SHARE_DENY_BOTH);
434+
stp->st_deny_bmap &= ~mask;
435+
}
436+
437+
/* test whether a given stateid is denying specific access */
438+
static inline bool
439+
test_deny(u32 deny, struct nfs4_ol_stateid *stp)
440+
{
441+
unsigned char mask = 1 << deny;
442+
443+
return (bool)(stp->st_deny_bmap & mask);
444+
}
445+
446+
static int nfs4_access_to_omode(u32 access)
447+
{
448+
switch (access & NFS4_SHARE_ACCESS_BOTH) {
449+
case NFS4_SHARE_ACCESS_READ:
450+
return O_RDONLY;
451+
case NFS4_SHARE_ACCESS_WRITE:
452+
return O_WRONLY;
453+
case NFS4_SHARE_ACCESS_BOTH:
454+
return O_RDWR;
455+
}
456+
WARN_ON_ONCE(1);
457+
return O_RDONLY;
458+
}
459+
460+
static inline int
461+
access_permit_read(struct nfs4_ol_stateid *stp)
462+
{
463+
return test_access(NFS4_SHARE_ACCESS_READ, stp) ||
464+
test_access(NFS4_SHARE_ACCESS_BOTH, stp) ||
465+
test_access(NFS4_SHARE_ACCESS_WRITE, stp);
466+
}
467+
468+
static inline int
469+
access_permit_write(struct nfs4_ol_stateid *stp)
470+
{
471+
return test_access(NFS4_SHARE_ACCESS_WRITE, stp) ||
472+
test_access(NFS4_SHARE_ACCESS_BOTH, stp);
473+
}
474+
357475
static inline struct nfs4_stateowner *
358476
nfs4_get_stateowner(struct nfs4_stateowner *sop)
359477
{
@@ -1150,108 +1268,6 @@ static unsigned int clientstr_hashval(struct xdr_netobj name)
11501268
return opaque_hashval(name.data, 8) & CLIENT_HASH_MASK;
11511269
}
11521270

1153-
/*
1154-
* We store the NONE, READ, WRITE, and BOTH bits separately in the
1155-
* st_{access,deny}_bmap field of the stateid, in order to track not
1156-
* only what share bits are currently in force, but also what
1157-
* combinations of share bits previous opens have used. This allows us
1158-
* to enforce the recommendation of rfc 3530 14.2.19 that the server
1159-
* return an error if the client attempt to downgrade to a combination
1160-
* of share bits not explicable by closing some of its previous opens.
1161-
*
1162-
* XXX: This enforcement is actually incomplete, since we don't keep
1163-
* track of access/deny bit combinations; so, e.g., we allow:
1164-
*
1165-
* OPEN allow read, deny write
1166-
* OPEN allow both, deny none
1167-
* DOWNGRADE allow read, deny none
1168-
*
1169-
* which we should reject.
1170-
*/
1171-
static unsigned int
1172-
bmap_to_share_mode(unsigned long bmap) {
1173-
int i;
1174-
unsigned int access = 0;
1175-
1176-
for (i = 1; i < 4; i++) {
1177-
if (test_bit(i, &bmap))
1178-
access |= i;
1179-
}
1180-
return access;
1181-
}
1182-
1183-
/* set share access for a given stateid */
1184-
static inline void
1185-
set_access(u32 access, struct nfs4_ol_stateid *stp)
1186-
{
1187-
unsigned char mask = 1 << access;
1188-
1189-
WARN_ON_ONCE(access > NFS4_SHARE_ACCESS_BOTH);
1190-
stp->st_access_bmap |= mask;
1191-
}
1192-
1193-
/* clear share access for a given stateid */
1194-
static inline void
1195-
clear_access(u32 access, struct nfs4_ol_stateid *stp)
1196-
{
1197-
unsigned char mask = 1 << access;
1198-
1199-
WARN_ON_ONCE(access > NFS4_SHARE_ACCESS_BOTH);
1200-
stp->st_access_bmap &= ~mask;
1201-
}
1202-
1203-
/* test whether a given stateid has access */
1204-
static inline bool
1205-
test_access(u32 access, struct nfs4_ol_stateid *stp)
1206-
{
1207-
unsigned char mask = 1 << access;
1208-
1209-
return (bool)(stp->st_access_bmap & mask);
1210-
}
1211-
1212-
/* set share deny for a given stateid */
1213-
static inline void
1214-
set_deny(u32 deny, struct nfs4_ol_stateid *stp)
1215-
{
1216-
unsigned char mask = 1 << deny;
1217-
1218-
WARN_ON_ONCE(deny > NFS4_SHARE_DENY_BOTH);
1219-
stp->st_deny_bmap |= mask;
1220-
}
1221-
1222-
/* clear share deny for a given stateid */
1223-
static inline void
1224-
clear_deny(u32 deny, struct nfs4_ol_stateid *stp)
1225-
{
1226-
unsigned char mask = 1 << deny;
1227-
1228-
WARN_ON_ONCE(deny > NFS4_SHARE_DENY_BOTH);
1229-
stp->st_deny_bmap &= ~mask;
1230-
}
1231-
1232-
/* test whether a given stateid is denying specific access */
1233-
static inline bool
1234-
test_deny(u32 deny, struct nfs4_ol_stateid *stp)
1235-
{
1236-
unsigned char mask = 1 << deny;
1237-
1238-
return (bool)(stp->st_deny_bmap & mask);
1239-
}
1240-
1241-
static int nfs4_access_to_omode(u32 access)
1242-
{
1243-
switch (access & NFS4_SHARE_ACCESS_BOTH) {
1244-
case NFS4_SHARE_ACCESS_READ:
1245-
return O_RDONLY;
1246-
case NFS4_SHARE_ACCESS_WRITE:
1247-
return O_WRONLY;
1248-
case NFS4_SHARE_ACCESS_BOTH:
1249-
return O_RDWR;
1250-
}
1251-
WARN_ON_ONCE(1);
1252-
return O_RDONLY;
1253-
}
1254-
12551271
/*
12561272
* A stateid that had a deny mode associated with it is being released
12571273
* or downgraded. Recalculate the deny mode on the file.
@@ -5523,21 +5539,6 @@ static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stid *stp)
55235539
return nfs_ok;
55245540
}
55255541

5526-
static inline int
5527-
access_permit_read(struct nfs4_ol_stateid *stp)
5528-
{
5529-
return test_access(NFS4_SHARE_ACCESS_READ, stp) ||
5530-
test_access(NFS4_SHARE_ACCESS_BOTH, stp) ||
5531-
test_access(NFS4_SHARE_ACCESS_WRITE, stp);
5532-
}
5533-
5534-
static inline int
5535-
access_permit_write(struct nfs4_ol_stateid *stp)
5536-
{
5537-
return test_access(NFS4_SHARE_ACCESS_WRITE, stp) ||
5538-
test_access(NFS4_SHARE_ACCESS_BOTH, stp);
5539-
}
5540-
55415542
static
55425543
__be32 nfs4_check_openmode(struct nfs4_ol_stateid *stp, int flags)
55435544
{

0 commit comments

Comments
 (0)