Skip to content

Commit b10494a

Browse files
jhgorsedhowells
authored andcommitted
afs: implement acl setting
Implements the setting of ACLs in AFS by means of setting the afs.acl extended attribute on the file. Signed-off-by: Joe Gorse <jhgorse@gmail.com> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 260f082 commit b10494a

File tree

5 files changed

+110
-6
lines changed

5 files changed

+110
-6
lines changed

fs/afs/afs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum AFS_FS_Operations {
2020
FSFETCHACL = 131, /* AFS Fetch file ACL */
2121
FSFETCHSTATUS = 132, /* AFS Fetch file status */
2222
FSSTOREDATA = 133, /* AFS Store file data */
23+
FSSTOREACL = 134, /* AFS Store file ACL */
2324
FSSTORESTATUS = 135, /* AFS Store file status */
2425
FSREMOVEFILE = 136, /* AFS Remove a file */
2526
FSCREATEFILE = 137, /* AFS Create a file */

fs/afs/fsclient.c

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,10 @@ int afs_fs_create(struct afs_fs_cursor *fc,
836836
}
837837

838838
/*
839-
* deliver reply data to an FS.RemoveFile or FS.RemoveDir
839+
* Deliver reply data to any operation that returns file status and volume
840+
* sync.
840841
*/
841-
static int afs_deliver_fs_remove(struct afs_call *call)
842+
static int afs_deliver_fs_status_and_vol(struct afs_call *call)
842843
{
843844
struct afs_vnode *vnode = call->reply[0];
844845
const __be32 *bp;
@@ -868,14 +869,14 @@ static int afs_deliver_fs_remove(struct afs_call *call)
868869
static const struct afs_call_type afs_RXFSRemoveFile = {
869870
.name = "FS.RemoveFile",
870871
.op = afs_FS_RemoveFile,
871-
.deliver = afs_deliver_fs_remove,
872+
.deliver = afs_deliver_fs_status_and_vol,
872873
.destructor = afs_flat_call_destructor,
873874
};
874875

875876
static const struct afs_call_type afs_RXFSRemoveDir = {
876877
.name = "FS.RemoveDir",
877878
.op = afs_FS_RemoveDir,
878-
.deliver = afs_deliver_fs_remove,
879+
.deliver = afs_deliver_fs_status_and_vol,
879880
.destructor = afs_flat_call_destructor,
880881
};
881882

@@ -2513,3 +2514,55 @@ struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *fc)
25132514
afs_make_call(&fc->ac, call, GFP_KERNEL);
25142515
return (struct afs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
25152516
}
2517+
2518+
/*
2519+
* FS.StoreACL operation type
2520+
*/
2521+
static const struct afs_call_type afs_RXFSStoreACL = {
2522+
.name = "FS.StoreACL",
2523+
.op = afs_FS_StoreACL,
2524+
.deliver = afs_deliver_fs_status_and_vol,
2525+
.destructor = afs_flat_call_destructor,
2526+
};
2527+
2528+
/*
2529+
* Fetch the ACL for a file.
2530+
*/
2531+
int afs_fs_store_acl(struct afs_fs_cursor *fc, const struct afs_acl *acl)
2532+
{
2533+
struct afs_vnode *vnode = fc->vnode;
2534+
struct afs_call *call;
2535+
struct afs_net *net = afs_v2net(vnode);
2536+
size_t size;
2537+
__be32 *bp;
2538+
2539+
_enter(",%x,{%llx:%llu},,",
2540+
key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2541+
2542+
size = round_up(acl->size, 4);
2543+
call = afs_alloc_flat_call(net, &afs_RXFSStoreACL,
2544+
5 * 4 + size, (21 + 6) * 4);
2545+
if (!call) {
2546+
fc->ac.error = -ENOMEM;
2547+
return -ENOMEM;
2548+
}
2549+
2550+
call->key = fc->key;
2551+
call->reply[0] = vnode;
2552+
call->reply[2] = NULL; /* volsync */
2553+
2554+
/* marshall the parameters */
2555+
bp = call->request;
2556+
bp[0] = htonl(FSSTOREACL);
2557+
bp[1] = htonl(vnode->fid.vid);
2558+
bp[2] = htonl(vnode->fid.vnode);
2559+
bp[3] = htonl(vnode->fid.unique);
2560+
bp[4] = htonl(acl->size);
2561+
memcpy(&bp[5], acl->data, acl->size);
2562+
if (acl->size != size)
2563+
memset((void *)&bp[5] + acl->size, 0, size - acl->size);
2564+
2565+
trace_afs_make_fs_call(call, &vnode->fid);
2566+
afs_make_call(&fc->ac, call, GFP_KERNEL);
2567+
return afs_wait_for_call_to_complete(call, &fc->ac);
2568+
}

fs/afs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ struct afs_acl {
983983
};
984984

985985
extern struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *);
986+
extern int afs_fs_store_acl(struct afs_fs_cursor *, const struct afs_acl *);
986987

987988
/*
988989
* fs_probe.c

fs/afs/xattr.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,57 @@ static int afs_xattr_get_acl(const struct xattr_handler *handler,
8080
return ret;
8181
}
8282

83+
/*
84+
* Set a file's AFS3 ACL.
85+
*/
86+
static int afs_xattr_set_acl(const struct xattr_handler *handler,
87+
struct dentry *dentry,
88+
struct inode *inode, const char *name,
89+
const void *buffer, size_t size, int flags)
90+
{
91+
struct afs_fs_cursor fc;
92+
struct afs_vnode *vnode = AFS_FS_I(inode);
93+
struct afs_acl *acl = NULL;
94+
struct key *key;
95+
int ret;
96+
97+
if (flags == XATTR_CREATE)
98+
return -EINVAL;
99+
100+
key = afs_request_key(vnode->volume->cell);
101+
if (IS_ERR(key))
102+
return PTR_ERR(key);
103+
104+
acl = kmalloc(sizeof(*acl) + size, GFP_KERNEL);
105+
if (!acl) {
106+
key_put(key);
107+
return -ENOMEM;
108+
}
109+
110+
acl->size = size;
111+
memcpy(acl->data, buffer, size);
112+
113+
ret = -ERESTARTSYS;
114+
if (afs_begin_vnode_operation(&fc, vnode, key)) {
115+
while (afs_select_fileserver(&fc)) {
116+
fc.cb_break = afs_calc_vnode_cb_break(vnode);
117+
afs_fs_store_acl(&fc, acl);
118+
}
119+
120+
afs_check_for_remote_deletion(&fc, fc.vnode);
121+
afs_vnode_commit_status(&fc, vnode, fc.cb_break);
122+
ret = afs_end_vnode_operation(&fc);
123+
}
124+
125+
kfree(acl);
126+
key_put(key);
127+
return ret;
128+
}
129+
83130
static const struct xattr_handler afs_xattr_afs_acl_handler = {
84-
.name = "afs.acl",
85-
.get = afs_xattr_get_acl,
131+
.name = "afs.acl",
132+
.get = afs_xattr_get_acl,
133+
.set = afs_xattr_set_acl,
86134
};
87135

88136
/*

include/trace/events/afs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum afs_fs_operation {
3636
afs_FS_FetchACL = 131, /* AFS Fetch file ACL */
3737
afs_FS_FetchStatus = 132, /* AFS Fetch file status */
3838
afs_FS_StoreData = 133, /* AFS Store file data */
39+
afs_FS_StoreACL = 134, /* AFS Store file ACL */
3940
afs_FS_StoreStatus = 135, /* AFS Store file status */
4041
afs_FS_RemoveFile = 136, /* AFS Remove a file */
4142
afs_FS_CreateFile = 137, /* AFS Create a file */

0 commit comments

Comments
 (0)