Skip to content

Commit be080a6

Browse files
committed
afs: Overhaul permit caching
Overhaul permit caching in AFS by making it per-vnode and sharing permit lists where possible. When most of the fileserver operations are called, they return a status structure indicating the (revised) details of the vnode or vnodes involved in the operation. This includes the access mark derived from the ACL (named CallerAccess in the protocol definition file). This is cacheable and if the ACL changes, the server will tell us that it is breaking the callback promise, at which point we can discard the currently cached permits. With this patch, the afs_permits structure has, at the end, an array of { key, CallerAccess } elements, sorted by key pointer. This is then cached in a hash table so that it can be shared between vnodes with the same access permits. Permit lists can only be shared if they contain the exact same set of key->CallerAccess mappings. Note that that table is global rather than being per-net_ns. If the keys in a permit list cross net_ns boundaries, there is no problem sharing the cached permits, since the permits are just integer masks. Since permit lists pin keys, the permit cache also makes it easier for a future patch to find all occurrences of a key and remove them by means of setting the afs_permits::invalidated flag and then clearing the appropriate key pointer. In such an event, memory barriers will need adding. Lastly, the permit caching is skipped if the server has sent either a vnode-specific or an entire-server callback since the start of the operation. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent c435ee3 commit be080a6

File tree

9 files changed

+244
-187
lines changed

9 files changed

+244
-187
lines changed

fs/afs/afs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ struct afs_file_status {
136136
afs_access_t caller_access; /* access rights for authenticated caller */
137137
afs_access_t anon_access; /* access rights for unauthenticated caller */
138138
umode_t mode; /* UNIX mode */
139-
struct afs_fid parent; /* parent dir ID for non-dirs only */
140139
time_t mtime_client; /* last time client changed data */
141140
time_t mtime_server; /* last time server changed data */
142141
s32 lock_count; /* file lock count (0=UNLK -1=WRLCK +ve=#RDLCK */

fs/afs/flock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
383383
/* again, make sure we've got a callback on this file and, again, make
384384
* sure that our view of the data version is up to date (we ignore
385385
* errors incurred here and deal with the consequences elsewhere) */
386-
afs_vnode_fetch_status(vnode, NULL, key, false);
386+
afs_vnode_fetch_status(vnode, key, false);
387387

388388
error:
389389
spin_unlock(&inode->i_lock);
@@ -455,7 +455,7 @@ static int afs_do_getlk(struct file *file, struct file_lock *fl)
455455
posix_test_lock(file, fl);
456456
if (fl->fl_type == F_UNLCK) {
457457
/* no local locks; consult the server */
458-
ret = afs_vnode_fetch_status(vnode, NULL, key, true);
458+
ret = afs_vnode_fetch_status(vnode, key, true);
459459
if (ret < 0)
460460
goto error;
461461
lock_count = vnode->status.lock_count;

fs/afs/fsclient.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
7878
EXTRACT(status->caller_access); /* call ticket dependent */
7979
EXTRACT(status->anon_access);
8080
EXTRACT(status->mode);
81-
EXTRACT(status->parent.vnode);
82-
EXTRACT(status->parent.unique);
81+
bp++; /* parent.vnode */
82+
bp++; /* parent.unique */
8383
bp++; /* seg size */
8484
status->mtime_client = ntohl(*bp++);
8585
status->mtime_server = ntohl(*bp++);
@@ -103,7 +103,6 @@ static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
103103
status->mtime_client, status->mtime_server);
104104

105105
if (vnode) {
106-
status->parent.vid = vnode->fid.vid;
107106
if (changed && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
108107
_debug("vnode changed");
109108
i_size_write(&vnode->vfs_inode, size);

fs/afs/inode.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,
238238

239239
if (!status) {
240240
/* it's a remotely extant inode */
241-
ret = afs_vnode_fetch_status(vnode, NULL, key, true);
241+
ret = afs_vnode_fetch_status(vnode, key, true);
242242
if (ret < 0)
243243
goto bad_inode;
244244
} else {
@@ -358,7 +358,7 @@ int afs_validate(struct afs_vnode *vnode, struct key *key)
358358
* access */
359359
if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
360360
_debug("not promised");
361-
ret = afs_vnode_fetch_status(vnode, NULL, key, false);
361+
ret = afs_vnode_fetch_status(vnode, key, false);
362362
if (ret < 0) {
363363
if (ret == -ENOENT) {
364364
set_bit(AFS_VNODE_DELETED, &vnode->flags);
@@ -431,7 +431,6 @@ int afs_drop_inode(struct inode *inode)
431431
*/
432432
void afs_evict_inode(struct inode *inode)
433433
{
434-
struct afs_permits *permits;
435434
struct afs_vnode *vnode;
436435

437436
vnode = AFS_FS_I(inode);
@@ -460,13 +459,7 @@ void afs_evict_inode(struct inode *inode)
460459
vnode->cache = NULL;
461460
#endif
462461

463-
mutex_lock(&vnode->permits_lock);
464-
permits = vnode->permits;
465-
RCU_INIT_POINTER(vnode->permits, NULL);
466-
mutex_unlock(&vnode->permits_lock);
467-
if (permits)
468-
call_rcu(&permits->rcu, afs_zap_permits);
469-
462+
afs_put_permits(vnode->permit_cache);
470463
_leave("");
471464
}
472465

fs/afs/internal.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ struct afs_vnode {
389389
#ifdef CONFIG_AFS_FSCACHE
390390
struct fscache_cookie *cache; /* caching cookie */
391391
#endif
392-
struct afs_permits *permits; /* cache of permits so far obtained */
393-
struct mutex permits_lock; /* lock for altering permits list */
392+
struct afs_permits *permit_cache; /* cache of permits so far obtained */
394393
struct mutex validate_lock; /* lock for validating this vnode */
395394
wait_queue_head_t update_waitq; /* status fetch waitqueue */
396395
int update_cnt; /* number of outstanding ops that will update the
@@ -411,8 +410,6 @@ struct afs_vnode {
411410
#define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */
412411
#define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */
413412

414-
long acl_order; /* ACL check count (callback break count) */
415-
416413
struct list_head writebacks; /* alterations in pagecache that need writing */
417414
struct list_head pending_locks; /* locks waiting to be granted */
418415
struct list_head granted_locks; /* locks granted on this file */
@@ -435,16 +432,21 @@ struct afs_vnode {
435432
*/
436433
struct afs_permit {
437434
struct key *key; /* RxRPC ticket holding a security context */
438-
afs_access_t access_mask; /* access mask for this key */
435+
afs_access_t access; /* CallerAccess value for this key */
439436
};
440437

441438
/*
442-
* cache of security records from attempts to access a vnode
439+
* Immutable cache of CallerAccess records from attempts to access vnodes.
440+
* These may be shared between multiple vnodes.
443441
*/
444442
struct afs_permits {
445-
struct rcu_head rcu; /* disposal procedure */
446-
int count; /* number of records */
447-
struct afs_permit permits[0]; /* the permits so far examined */
443+
struct rcu_head rcu;
444+
struct hlist_node hash_node; /* Link in hash */
445+
unsigned long h; /* Hash value for this permit list */
446+
refcount_t usage;
447+
unsigned short nr_permits; /* Number of records */
448+
bool invalidated; /* Invalidated due to key change */
449+
struct afs_permit permits[]; /* List of permits sorted by key pointer */
448450
};
449451

450452
/*
@@ -682,11 +684,13 @@ static inline int afs_transfer_reply(struct afs_call *call)
682684
/*
683685
* security.c
684686
*/
687+
extern void afs_put_permits(struct afs_permits *);
685688
extern void afs_clear_permits(struct afs_vnode *);
686-
extern void afs_cache_permit(struct afs_vnode *, struct key *, long);
689+
extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
687690
extern void afs_zap_permits(struct rcu_head *);
688691
extern struct key *afs_request_key(struct afs_cell *);
689692
extern int afs_permission(struct inode *, int);
693+
extern void __exit afs_clean_up_permit_cache(void);
690694

691695
/*
692696
* server.c
@@ -757,8 +761,7 @@ static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
757761

758762
extern void afs_vnode_finalise_status_update(struct afs_vnode *,
759763
struct afs_server *);
760-
extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *,
761-
struct key *, bool);
764+
extern int afs_vnode_fetch_status(struct afs_vnode *, struct key *, bool);
762765
extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
763766
struct afs_read *);
764767
extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *,

fs/afs/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static void __exit afs_exit(void)
186186
destroy_workqueue(afs_vlocation_update_worker);
187187
destroy_workqueue(afs_async_calls);
188188
destroy_workqueue(afs_wq);
189+
afs_clean_up_permit_cache();
189190
rcu_barrier();
190191
}
191192

0 commit comments

Comments
 (0)