Skip to content

Commit 215804a

Browse files
committed
afs: Introduce a file-private data record
Introduce a file-private data record for kAFS and put the key into it rather than storing the key in file->private_data. Signed-off-by: David Howells <[email protected]>
1 parent 83732ec commit 215804a

File tree

6 files changed

+51
-20
lines changed

6 files changed

+51
-20
lines changed

fs/afs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx,
396396
*/
397397
static int afs_readdir(struct file *file, struct dir_context *ctx)
398398
{
399-
return afs_dir_iterate(file_inode(file), ctx, file->private_data);
399+
return afs_dir_iterate(file_inode(file), ctx, afs_file_key(file));
400400
}
401401

402402
/*

fs/afs/file.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,40 @@ const struct address_space_operations afs_fs_aops = {
6868
int afs_open(struct inode *inode, struct file *file)
6969
{
7070
struct afs_vnode *vnode = AFS_FS_I(inode);
71+
struct afs_file *af;
7172
struct key *key;
7273
int ret;
7374

7475
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
7576

7677
key = afs_request_key(vnode->volume->cell);
7778
if (IS_ERR(key)) {
78-
_leave(" = %ld [key]", PTR_ERR(key));
79-
return PTR_ERR(key);
79+
ret = PTR_ERR(key);
80+
goto error;
8081
}
8182

82-
ret = afs_validate(vnode, key);
83-
if (ret < 0) {
84-
_leave(" = %d [val]", ret);
85-
return ret;
83+
af = kzalloc(sizeof(*af), GFP_KERNEL);
84+
if (!af) {
85+
ret = -ENOMEM;
86+
goto error_key;
8687
}
8788

88-
file->private_data = key;
89+
ret = afs_validate(vnode, key);
90+
if (ret < 0)
91+
goto error_af;
92+
93+
af->key = key;
94+
file->private_data = af;
8995
_leave(" = 0");
9096
return 0;
97+
98+
error_af:
99+
kfree(af);
100+
error_key:
101+
key_put(key);
102+
error:
103+
_leave(" = %d", ret);
104+
return ret;
91105
}
92106

93107
/*
@@ -96,10 +110,13 @@ int afs_open(struct inode *inode, struct file *file)
96110
int afs_release(struct inode *inode, struct file *file)
97111
{
98112
struct afs_vnode *vnode = AFS_FS_I(inode);
113+
struct afs_file *af = file->private_data;
99114

100115
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
101116

102-
key_put(file->private_data);
117+
file->private_data = NULL;
118+
key_put(af->key);
119+
kfree(af);
103120
_leave(" = 0");
104121
return 0;
105122
}
@@ -295,7 +312,7 @@ static int afs_readpage(struct file *file, struct page *page)
295312
int ret;
296313

297314
if (file) {
298-
key = file->private_data;
315+
key = afs_file_key(file);
299316
ASSERT(key != NULL);
300317
ret = afs_page_filler(key, page);
301318
} else {
@@ -346,7 +363,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
346363
struct afs_read *req;
347364
struct list_head *p;
348365
struct page *first, *page;
349-
struct key *key = file->private_data;
366+
struct key *key = afs_file_key(file);
350367
pgoff_t index;
351368
int ret, n, i;
352369

@@ -442,7 +459,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
442459
static int afs_readpages(struct file *file, struct address_space *mapping,
443460
struct list_head *pages, unsigned nr_pages)
444461
{
445-
struct key *key = file->private_data;
462+
struct key *key = afs_file_key(file);
446463
struct afs_vnode *vnode;
447464
int ret = 0;
448465

fs/afs/flock.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void afs_lock_work(struct work_struct *work)
206206
BUG();
207207
fl = list_entry(vnode->granted_locks.next,
208208
struct file_lock, fl_u.afs.link);
209-
key = key_get(fl->fl_file->private_data);
209+
key = key_get(afs_file_key(fl->fl_file));
210210
spin_unlock(&vnode->lock);
211211

212212
ret = afs_extend_lock(vnode, key);
@@ -240,7 +240,7 @@ void afs_lock_work(struct work_struct *work)
240240
BUG();
241241
fl = list_entry(vnode->pending_locks.next,
242242
struct file_lock, fl_u.afs.link);
243-
key = key_get(fl->fl_file->private_data);
243+
key = key_get(afs_file_key(fl->fl_file));
244244
type = (fl->fl_type == F_RDLCK) ?
245245
AFS_LOCK_READ : AFS_LOCK_WRITE;
246246
spin_unlock(&vnode->lock);
@@ -318,7 +318,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
318318
struct inode *inode = file_inode(file);
319319
struct afs_vnode *vnode = AFS_FS_I(inode);
320320
afs_lock_type_t type;
321-
struct key *key = file->private_data;
321+
struct key *key = afs_file_key(file);
322322
int ret;
323323

324324
_enter("{%x:%u},%u", vnode->fid.vid, vnode->fid.vnode, fl->fl_type);
@@ -500,7 +500,7 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl)
500500
static int afs_do_unlk(struct file *file, struct file_lock *fl)
501501
{
502502
struct afs_vnode *vnode = AFS_FS_I(file->f_mapping->host);
503-
struct key *key = file->private_data;
503+
struct key *key = afs_file_key(file);
504504
int ret;
505505

506506
_enter("{%x:%u},%u", vnode->fid.vid, vnode->fid.vnode, fl->fl_type);
@@ -535,7 +535,7 @@ static int afs_do_unlk(struct file *file, struct file_lock *fl)
535535
static int afs_do_getlk(struct file *file, struct file_lock *fl)
536536
{
537537
struct afs_vnode *vnode = AFS_FS_I(file->f_mapping->host);
538-
struct key *key = file->private_data;
538+
struct key *key = afs_file_key(file);
539539
int ret, lock_count;
540540

541541
_enter("");

fs/afs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr)
520520
}
521521

522522
if (attr->ia_valid & ATTR_FILE) {
523-
key = attr->ia_file->private_data;
523+
key = afs_file_key(attr->ia_file);
524524
} else {
525525
key = afs_request_key(vnode->volume->cell);
526526
if (IS_ERR(key)) {

fs/afs/internal.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ struct afs_call_type {
138138
void (*work)(struct work_struct *work);
139139
};
140140

141+
/*
142+
* AFS open file information record. Pointed to by file->private_data.
143+
*/
144+
struct afs_file {
145+
struct key *key; /* The key this file was opened with */
146+
};
147+
148+
static inline struct key *afs_file_key(struct file *file)
149+
{
150+
struct afs_file *af = file->private_data;
151+
152+
return af->key;
153+
}
154+
141155
/*
142156
* Record of an outstanding read operation on a vnode.
143157
*/

fs/afs/write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
128128
struct afs_writeback *candidate, *wb;
129129
struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
130130
struct page *page;
131-
struct key *key = file->private_data;
131+
struct key *key = afs_file_key(file);
132132
unsigned from = pos & (PAGE_SIZE - 1);
133133
unsigned to = from + len;
134134
pgoff_t index = pos >> PAGE_SHIFT;
@@ -255,7 +255,7 @@ int afs_write_end(struct file *file, struct address_space *mapping,
255255
struct page *page, void *fsdata)
256256
{
257257
struct afs_vnode *vnode = AFS_FS_I(file_inode(file));
258-
struct key *key = file->private_data;
258+
struct key *key = afs_file_key(file);
259259
loff_t i_size, maybe_i_size;
260260
int ret;
261261

0 commit comments

Comments
 (0)