David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 1 | /* AFS File Server client stubs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 3 | * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/sched.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 14 | #include <linux/circ_buf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "internal.h" |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 16 | #include "afs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 19 | * decode an AFSFetchStatus block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 21 | static void xdr_decode_AFSFetchStatus(const __be32 **_bp, |
| 22 | struct afs_vnode *vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 24 | const __be32 *bp = *_bp; |
| 25 | umode_t mode; |
| 26 | u64 data_version; |
| 27 | u32 changed = 0; /* becomes non-zero if ctime-type changes seen */ |
| 28 | |
| 29 | #define EXTRACT(DST) \ |
| 30 | do { \ |
| 31 | u32 x = ntohl(*bp++); \ |
| 32 | changed |= DST - x; \ |
| 33 | DST = x; \ |
| 34 | } while (0) |
| 35 | |
| 36 | vnode->status.if_version = ntohl(*bp++); |
| 37 | EXTRACT(vnode->status.type); |
| 38 | vnode->status.nlink = ntohl(*bp++); |
| 39 | EXTRACT(vnode->status.size); |
| 40 | data_version = ntohl(*bp++); |
| 41 | EXTRACT(vnode->status.author); |
| 42 | EXTRACT(vnode->status.owner); |
| 43 | EXTRACT(vnode->status.caller_access); /* call ticket dependent */ |
| 44 | EXTRACT(vnode->status.anon_access); |
| 45 | EXTRACT(vnode->status.mode); |
| 46 | vnode->status.parent.vid = vnode->fid.vid; |
| 47 | EXTRACT(vnode->status.parent.vnode); |
| 48 | EXTRACT(vnode->status.parent.unique); |
| 49 | bp++; /* seg size */ |
| 50 | vnode->status.mtime_client = ntohl(*bp++); |
| 51 | vnode->status.mtime_server = ntohl(*bp++); |
| 52 | bp++; /* group */ |
| 53 | bp++; /* sync counter */ |
| 54 | data_version |= (u64) ntohl(*bp++) << 32; |
| 55 | bp++; /* spare2 */ |
| 56 | bp++; /* spare3 */ |
| 57 | bp++; /* spare4 */ |
| 58 | *_bp = bp; |
| 59 | |
| 60 | if (changed) { |
| 61 | _debug("vnode changed"); |
| 62 | set_bit(AFS_VNODE_CHANGED, &vnode->flags); |
| 63 | vnode->vfs_inode.i_uid = vnode->status.owner; |
| 64 | vnode->vfs_inode.i_size = vnode->status.size; |
| 65 | vnode->vfs_inode.i_version = vnode->fid.unique; |
| 66 | |
| 67 | vnode->status.mode &= S_IALLUGO; |
| 68 | mode = vnode->vfs_inode.i_mode; |
| 69 | mode &= ~S_IALLUGO; |
| 70 | mode |= vnode->status.mode; |
| 71 | vnode->vfs_inode.i_mode = mode; |
| 72 | } |
| 73 | |
| 74 | _debug("vnode time %lx, %lx", |
| 75 | vnode->status.mtime_client, vnode->status.mtime_server); |
| 76 | vnode->vfs_inode.i_ctime.tv_sec = vnode->status.mtime_server; |
| 77 | vnode->vfs_inode.i_mtime = vnode->vfs_inode.i_ctime; |
| 78 | vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime; |
| 79 | |
| 80 | if (vnode->status.data_version != data_version) { |
| 81 | _debug("vnode modified %llx", data_version); |
| 82 | vnode->status.data_version = data_version; |
| 83 | set_bit(AFS_VNODE_MODIFIED, &vnode->flags); |
| 84 | set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 89 | * decode an AFSCallBack block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 91 | static void xdr_decode_AFSCallBack(const __be32 **_bp, struct afs_vnode *vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 93 | const __be32 *bp = *_bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 95 | vnode->cb_version = ntohl(*bp++); |
| 96 | vnode->cb_expiry = ntohl(*bp++); |
| 97 | vnode->cb_type = ntohl(*bp++); |
| 98 | vnode->cb_expires = vnode->cb_expiry + get_seconds(); |
| 99 | *_bp = bp; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 103 | * decode an AFSVolSync block |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 105 | static void xdr_decode_AFSVolSync(const __be32 **_bp, |
| 106 | struct afs_volsync *volsync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 108 | const __be32 *bp = *_bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 110 | volsync->creation = ntohl(*bp++); |
| 111 | bp++; /* spare2 */ |
| 112 | bp++; /* spare3 */ |
| 113 | bp++; /* spare4 */ |
| 114 | bp++; /* spare5 */ |
| 115 | bp++; /* spare6 */ |
| 116 | *_bp = bp; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 117 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 118 | |
| 119 | /* |
| 120 | * deliver reply data to an FS.FetchStatus |
| 121 | */ |
| 122 | static int afs_deliver_fs_fetch_status(struct afs_call *call, |
| 123 | struct sk_buff *skb, bool last) |
| 124 | { |
| 125 | const __be32 *bp; |
| 126 | |
| 127 | _enter(",,%u", last); |
| 128 | |
| 129 | afs_transfer_reply(call, skb); |
| 130 | if (!last) |
| 131 | return 0; |
| 132 | |
| 133 | if (call->reply_size != call->reply_max) |
| 134 | return -EBADMSG; |
| 135 | |
| 136 | /* unmarshall the reply once we've received all of it */ |
| 137 | bp = call->buffer; |
| 138 | xdr_decode_AFSFetchStatus(&bp, call->reply); |
| 139 | xdr_decode_AFSCallBack(&bp, call->reply); |
| 140 | if (call->reply2) |
| 141 | xdr_decode_AFSVolSync(&bp, call->reply2); |
| 142 | |
| 143 | _leave(" = 0 [done]"); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * FS.FetchStatus operation type |
| 149 | */ |
| 150 | static const struct afs_call_type afs_RXFSFetchStatus = { |
| 151 | .deliver = afs_deliver_fs_fetch_status, |
| 152 | .abort_to_error = afs_abort_to_error, |
| 153 | .destructor = afs_flat_call_destructor, |
| 154 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* |
| 157 | * fetch the status information for a file |
| 158 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 159 | int afs_fs_fetch_file_status(struct afs_server *server, |
| 160 | struct afs_vnode *vnode, |
| 161 | struct afs_volsync *volsync, |
| 162 | const struct afs_wait_mode *wait_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 164 | struct afs_call *call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | __be32 *bp; |
| 166 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 167 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 169 | call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, 120); |
| 170 | if (!call) |
| 171 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 173 | call->reply = vnode; |
| 174 | call->reply2 = volsync; |
| 175 | call->service_id = FS_SERVICE; |
| 176 | call->port = htons(AFS_FS_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 179 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | bp[0] = htonl(FSFETCHSTATUS); |
| 181 | bp[1] = htonl(vnode->fid.vid); |
| 182 | bp[2] = htonl(vnode->fid.vnode); |
| 183 | bp[3] = htonl(vnode->fid.unique); |
| 184 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 185 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 189 | * deliver reply data to an FS.FetchData |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 191 | static int afs_deliver_fs_fetch_data(struct afs_call *call, |
| 192 | struct sk_buff *skb, bool last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 194 | const __be32 *bp; |
| 195 | struct page *page; |
| 196 | void *buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 198 | |
| 199 | _enter("{%u},{%u},%d", call->unmarshall, skb->len, last); |
| 200 | |
| 201 | switch (call->unmarshall) { |
| 202 | case 0: |
| 203 | call->offset = 0; |
| 204 | call->unmarshall++; |
| 205 | |
| 206 | /* extract the returned data length */ |
| 207 | case 1: |
| 208 | _debug("extract data length"); |
| 209 | ret = afs_extract_data(call, skb, last, &call->tmp, 4); |
| 210 | switch (ret) { |
| 211 | case 0: break; |
| 212 | case -EAGAIN: return 0; |
| 213 | default: return ret; |
| 214 | } |
| 215 | |
| 216 | call->count = ntohl(call->tmp); |
| 217 | _debug("DATA length: %u", call->count); |
| 218 | if (call->count > PAGE_SIZE) |
| 219 | return -EBADMSG; |
| 220 | call->offset = 0; |
| 221 | call->unmarshall++; |
| 222 | |
| 223 | if (call->count < PAGE_SIZE) { |
| 224 | buffer = kmap_atomic(call->reply3, KM_USER0); |
| 225 | memset(buffer + PAGE_SIZE - call->count, 0, |
| 226 | call->count); |
| 227 | kunmap_atomic(buffer, KM_USER0); |
| 228 | } |
| 229 | |
| 230 | /* extract the returned data */ |
| 231 | case 2: |
| 232 | _debug("extract data"); |
| 233 | page = call->reply3; |
| 234 | buffer = kmap_atomic(page, KM_USER0); |
| 235 | ret = afs_extract_data(call, skb, last, buffer, call->count); |
| 236 | kunmap_atomic(buffer, KM_USER0); |
| 237 | switch (ret) { |
| 238 | case 0: break; |
| 239 | case -EAGAIN: return 0; |
| 240 | default: return ret; |
| 241 | } |
| 242 | |
| 243 | call->offset = 0; |
| 244 | call->unmarshall++; |
| 245 | |
| 246 | /* extract the metadata */ |
| 247 | case 3: |
| 248 | ret = afs_extract_data(call, skb, last, call->buffer, 120); |
| 249 | switch (ret) { |
| 250 | case 0: break; |
| 251 | case -EAGAIN: return 0; |
| 252 | default: return ret; |
| 253 | } |
| 254 | |
| 255 | bp = call->buffer; |
| 256 | xdr_decode_AFSFetchStatus(&bp, call->reply); |
| 257 | xdr_decode_AFSCallBack(&bp, call->reply); |
| 258 | if (call->reply2) |
| 259 | xdr_decode_AFSVolSync(&bp, call->reply2); |
| 260 | |
| 261 | call->offset = 0; |
| 262 | call->unmarshall++; |
| 263 | |
| 264 | case 4: |
| 265 | _debug("trailer"); |
| 266 | if (skb->len != 0) |
| 267 | return -EBADMSG; |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | if (!last) |
| 272 | return 0; |
| 273 | |
| 274 | _leave(" = 0 [done]"); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * FS.FetchData operation type |
| 280 | */ |
| 281 | static const struct afs_call_type afs_RXFSFetchData = { |
| 282 | .deliver = afs_deliver_fs_fetch_data, |
| 283 | .abort_to_error = afs_abort_to_error, |
| 284 | .destructor = afs_flat_call_destructor, |
| 285 | }; |
| 286 | |
| 287 | /* |
| 288 | * fetch data from a file |
| 289 | */ |
| 290 | int afs_fs_fetch_data(struct afs_server *server, |
| 291 | struct afs_vnode *vnode, |
| 292 | off_t offset, size_t length, |
| 293 | struct page *buffer, |
| 294 | struct afs_volsync *volsync, |
| 295 | const struct afs_wait_mode *wait_mode) |
| 296 | { |
| 297 | struct afs_call *call; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | __be32 *bp; |
| 299 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 300 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 302 | call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, 120); |
| 303 | if (!call) |
| 304 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 306 | call->reply = vnode; |
| 307 | call->reply2 = volsync; |
| 308 | call->reply3 = buffer; |
| 309 | call->service_id = FS_SERVICE; |
| 310 | call->port = htons(AFS_FS_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 313 | bp = call->request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | bp[0] = htonl(FSFETCHDATA); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 315 | bp[1] = htonl(vnode->fid.vid); |
| 316 | bp[2] = htonl(vnode->fid.vnode); |
| 317 | bp[3] = htonl(vnode->fid.unique); |
| 318 | bp[4] = htonl(offset); |
| 319 | bp[5] = htonl(length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 321 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 325 | * deliver reply data to an FS.GiveUpCallBacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 327 | static int afs_deliver_fs_give_up_callbacks(struct afs_call *call, |
| 328 | struct sk_buff *skb, bool last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 330 | _enter(",{%u},%d", skb->len, last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 332 | if (skb->len > 0) |
| 333 | return -EBADMSG; /* shouldn't be any reply data */ |
| 334 | return 0; |
| 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 337 | /* |
| 338 | * FS.GiveUpCallBacks operation type |
| 339 | */ |
| 340 | static const struct afs_call_type afs_RXFSGiveUpCallBacks = { |
| 341 | .deliver = afs_deliver_fs_give_up_callbacks, |
| 342 | .abort_to_error = afs_abort_to_error, |
| 343 | .destructor = afs_flat_call_destructor, |
| 344 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 346 | /* |
| 347 | * give up a set of callbacks |
| 348 | * - the callbacks are held in the server->cb_break ring |
| 349 | */ |
| 350 | int afs_fs_give_up_callbacks(struct afs_server *server, |
| 351 | const struct afs_wait_mode *wait_mode) |
| 352 | { |
| 353 | struct afs_call *call; |
| 354 | size_t ncallbacks; |
| 355 | __be32 *bp, *tp; |
| 356 | int loop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 358 | ncallbacks = CIRC_CNT(server->cb_break_head, server->cb_break_tail, |
| 359 | ARRAY_SIZE(server->cb_break)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 361 | _enter("{%zu},", ncallbacks); |
| 362 | |
| 363 | if (ncallbacks == 0) |
| 364 | return 0; |
| 365 | if (ncallbacks > AFSCBMAX) |
| 366 | ncallbacks = AFSCBMAX; |
| 367 | |
| 368 | _debug("break %zu callbacks", ncallbacks); |
| 369 | |
| 370 | call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks, |
| 371 | 12 + ncallbacks * 6 * 4, 0); |
| 372 | if (!call) |
| 373 | return -ENOMEM; |
| 374 | |
| 375 | call->service_id = FS_SERVICE; |
| 376 | call->port = htons(AFS_FS_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | /* marshall the parameters */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 379 | bp = call->request; |
| 380 | tp = bp + 2 + ncallbacks * 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | *bp++ = htonl(FSGIVEUPCALLBACKS); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 382 | *bp++ = htonl(ncallbacks); |
| 383 | *tp++ = htonl(ncallbacks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 385 | atomic_sub(ncallbacks, &server->cb_break_n); |
| 386 | for (loop = ncallbacks; loop > 0; loop--) { |
| 387 | struct afs_callback *cb = |
| 388 | &server->cb_break[server->cb_break_tail]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 390 | *bp++ = htonl(cb->fid.vid); |
| 391 | *bp++ = htonl(cb->fid.vnode); |
| 392 | *bp++ = htonl(cb->fid.unique); |
| 393 | *tp++ = htonl(cb->version); |
| 394 | *tp++ = htonl(cb->expiry); |
| 395 | *tp++ = htonl(cb->type); |
| 396 | smp_mb(); |
| 397 | server->cb_break_tail = |
| 398 | (server->cb_break_tail + 1) & |
| 399 | (ARRAY_SIZE(server->cb_break) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 402 | ASSERT(ncallbacks > 0); |
| 403 | wake_up_nr(&server->cb_break_waitq, ncallbacks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 405 | return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 406 | } |