Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Mostly platform independent upcall operations to Venus: |
| 3 | * -- upcalls |
| 4 | * -- upcall routines |
| 5 | * |
| 6 | * Linux 2.0 version |
| 7 | * Copyright (C) 1996 Peter J. Braam <braam@maths.ox.ac.uk>, |
| 8 | * Michael Callahan <callahan@maths.ox.ac.uk> |
| 9 | * |
| 10 | * Redone for Linux 2.1 |
| 11 | * Copyright (C) 1997 Carnegie Mellon University |
| 12 | * |
| 13 | * Carnegie Mellon University encourages users of this code to contribute |
| 14 | * improvements to the Coda project. Contact Peter Braam <coda@cs.cmu.edu>. |
| 15 | */ |
| 16 | |
| 17 | #include <asm/system.h> |
| 18 | #include <linux/signal.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 19 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/types.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/time.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/file.h> |
| 26 | #include <linux/stat.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/uaccess.h> |
| 31 | #include <linux/vmalloc.h> |
| 32 | #include <linux/vfs.h> |
| 33 | |
| 34 | #include <linux/coda.h> |
| 35 | #include <linux/coda_linux.h> |
| 36 | #include <linux/coda_psdev.h> |
| 37 | #include <linux/coda_fs_i.h> |
| 38 | #include <linux/coda_cache.h> |
Jan Harkes | 3cf01f2 | 2007-07-19 01:48:51 -0700 | [diff] [blame] | 39 | |
| 40 | #include "coda_int.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 42 | static int coda_upcall(struct venus_comm *vc, int inSize, int *outSize, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | union inputArgs *buffer); |
| 44 | |
| 45 | static void *alloc_upcall(int opcode, int size) |
| 46 | { |
| 47 | union inputArgs *inp; |
| 48 | |
| 49 | CODA_ALLOC(inp, union inputArgs *, size); |
| 50 | if (!inp) |
| 51 | return ERR_PTR(-ENOMEM); |
| 52 | |
| 53 | inp->ih.opcode = opcode; |
| 54 | inp->ih.pid = current->pid; |
Pavel Emelianov | a47afb0 | 2007-10-18 23:39:46 -0700 | [diff] [blame] | 55 | inp->ih.pgid = task_pgrp_nr(current); |
David Howells | 97b7702 | 2008-11-14 10:38:48 +1100 | [diff] [blame] | 56 | inp->ih.uid = current_fsuid(); |
Adrian Bunk | de0ca06 | 2008-07-25 01:46:34 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return (void*)inp; |
| 59 | } |
| 60 | |
| 61 | #define UPARG(op)\ |
| 62 | do {\ |
| 63 | inp = (union inputArgs *)alloc_upcall(op, insize); \ |
| 64 | if (IS_ERR(inp)) { return PTR_ERR(inp); }\ |
| 65 | outp = (union outputArgs *)(inp); \ |
| 66 | outsize = insize; \ |
| 67 | } while (0) |
| 68 | |
| 69 | #define INSIZE(tag) sizeof(struct coda_ ## tag ## _in) |
| 70 | #define OUTSIZE(tag) sizeof(struct coda_ ## tag ## _out) |
| 71 | #define SIZE(tag) max_t(unsigned int, INSIZE(tag), OUTSIZE(tag)) |
| 72 | |
| 73 | |
| 74 | /* the upcalls */ |
| 75 | int venus_rootfid(struct super_block *sb, struct CodaFid *fidp) |
| 76 | { |
| 77 | union inputArgs *inp; |
| 78 | union outputArgs *outp; |
| 79 | int insize, outsize, error; |
| 80 | |
| 81 | insize = SIZE(root); |
| 82 | UPARG(CODA_ROOT); |
| 83 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 84 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 85 | if (!error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | *fidp = outp->coda_root.VFid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | CODA_FREE(inp, insize); |
| 89 | return error; |
| 90 | } |
| 91 | |
| 92 | int venus_getattr(struct super_block *sb, struct CodaFid *fid, |
| 93 | struct coda_vattr *attr) |
| 94 | { |
| 95 | union inputArgs *inp; |
| 96 | union outputArgs *outp; |
| 97 | int insize, outsize, error; |
| 98 | |
| 99 | insize = SIZE(getattr); |
| 100 | UPARG(CODA_GETATTR); |
| 101 | inp->coda_getattr.VFid = *fid; |
| 102 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 103 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 104 | if (!error) |
| 105 | *attr = outp->coda_getattr.attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | CODA_FREE(inp, insize); |
| 108 | return error; |
| 109 | } |
| 110 | |
| 111 | int venus_setattr(struct super_block *sb, struct CodaFid *fid, |
| 112 | struct coda_vattr *vattr) |
| 113 | { |
| 114 | union inputArgs *inp; |
| 115 | union outputArgs *outp; |
| 116 | int insize, outsize, error; |
| 117 | |
| 118 | insize = SIZE(setattr); |
| 119 | UPARG(CODA_SETATTR); |
| 120 | |
| 121 | inp->coda_setattr.VFid = *fid; |
| 122 | inp->coda_setattr.attr = *vattr; |
| 123 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 124 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | CODA_FREE(inp, insize); |
| 127 | return error; |
| 128 | } |
| 129 | |
| 130 | int venus_lookup(struct super_block *sb, struct CodaFid *fid, |
| 131 | const char *name, int length, int * type, |
| 132 | struct CodaFid *resfid) |
| 133 | { |
| 134 | union inputArgs *inp; |
| 135 | union outputArgs *outp; |
| 136 | int insize, outsize, error; |
| 137 | int offset; |
| 138 | |
| 139 | offset = INSIZE(lookup); |
| 140 | insize = max_t(unsigned int, offset + length +1, OUTSIZE(lookup)); |
| 141 | UPARG(CODA_LOOKUP); |
| 142 | |
| 143 | inp->coda_lookup.VFid = *fid; |
| 144 | inp->coda_lookup.name = offset; |
| 145 | inp->coda_lookup.flags = CLU_CASE_SENSITIVE; |
| 146 | /* send Venus a null terminated string */ |
| 147 | memcpy((char *)(inp) + offset, name, length); |
| 148 | *((char *)inp + offset + length) = '\0'; |
| 149 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 150 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 151 | if (!error) { |
| 152 | *resfid = outp->coda_lookup.VFid; |
| 153 | *type = outp->coda_lookup.vtype; |
| 154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | CODA_FREE(inp, insize); |
| 157 | return error; |
| 158 | } |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, |
Jan Harkes | d3fec42 | 2007-07-21 04:37:26 -0700 | [diff] [blame] | 161 | vuid_t uid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
| 163 | union inputArgs *inp; |
| 164 | union outputArgs *outp; |
| 165 | int insize, outsize, error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | insize = SIZE(release); |
| 168 | UPARG(CODA_CLOSE); |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | inp->ih.uid = uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | inp->coda_close.VFid = *fid; |
| 172 | inp->coda_close.flags = flags; |
| 173 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 174 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | CODA_FREE(inp, insize); |
| 177 | return error; |
| 178 | } |
| 179 | |
| 180 | int venus_open(struct super_block *sb, struct CodaFid *fid, |
| 181 | int flags, struct file **fh) |
| 182 | { |
| 183 | union inputArgs *inp; |
| 184 | union outputArgs *outp; |
| 185 | int insize, outsize, error; |
| 186 | |
| 187 | insize = SIZE(open_by_fd); |
| 188 | UPARG(CODA_OPEN_BY_FD); |
| 189 | |
Jan Harkes | 38c2e43 | 2007-07-19 01:48:41 -0700 | [diff] [blame] | 190 | inp->coda_open_by_fd.VFid = *fid; |
| 191 | inp->coda_open_by_fd.flags = flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 193 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 38c2e43 | 2007-07-19 01:48:41 -0700 | [diff] [blame] | 194 | if (!error) |
| 195 | *fh = outp->coda_open_by_fd.fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | CODA_FREE(inp, insize); |
| 198 | return error; |
| 199 | } |
| 200 | |
| 201 | int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid, |
| 202 | const char *name, int length, |
| 203 | struct CodaFid *newfid, struct coda_vattr *attrs) |
| 204 | { |
| 205 | union inputArgs *inp; |
| 206 | union outputArgs *outp; |
| 207 | int insize, outsize, error; |
| 208 | int offset; |
| 209 | |
| 210 | offset = INSIZE(mkdir); |
| 211 | insize = max_t(unsigned int, offset + length + 1, OUTSIZE(mkdir)); |
| 212 | UPARG(CODA_MKDIR); |
| 213 | |
| 214 | inp->coda_mkdir.VFid = *dirfid; |
| 215 | inp->coda_mkdir.attr = *attrs; |
| 216 | inp->coda_mkdir.name = offset; |
| 217 | /* Venus must get null terminated string */ |
| 218 | memcpy((char *)(inp) + offset, name, length); |
| 219 | *((char *)inp + offset + length) = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 221 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 222 | if (!error) { |
| 223 | *attrs = outp->coda_mkdir.attr; |
| 224 | *newfid = outp->coda_mkdir.VFid; |
| 225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | CODA_FREE(inp, insize); |
| 228 | return error; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | int venus_rename(struct super_block *sb, struct CodaFid *old_fid, |
| 233 | struct CodaFid *new_fid, size_t old_length, |
| 234 | size_t new_length, const char *old_name, |
| 235 | const char *new_name) |
| 236 | { |
| 237 | union inputArgs *inp; |
| 238 | union outputArgs *outp; |
| 239 | int insize, outsize, error; |
| 240 | int offset, s; |
| 241 | |
| 242 | offset = INSIZE(rename); |
| 243 | insize = max_t(unsigned int, offset + new_length + old_length + 8, |
| 244 | OUTSIZE(rename)); |
| 245 | UPARG(CODA_RENAME); |
| 246 | |
| 247 | inp->coda_rename.sourceFid = *old_fid; |
| 248 | inp->coda_rename.destFid = *new_fid; |
| 249 | inp->coda_rename.srcname = offset; |
| 250 | |
| 251 | /* Venus must receive an null terminated string */ |
| 252 | s = ( old_length & ~0x3) +4; /* round up to word boundary */ |
| 253 | memcpy((char *)(inp) + offset, old_name, old_length); |
| 254 | *((char *)inp + offset + old_length) = '\0'; |
| 255 | |
| 256 | /* another null terminated string for Venus */ |
| 257 | offset += s; |
| 258 | inp->coda_rename.destname = offset; |
| 259 | s = ( new_length & ~0x3) +4; /* round up to word boundary */ |
| 260 | memcpy((char *)(inp) + offset, new_name, new_length); |
| 261 | *((char *)inp + offset + new_length) = '\0'; |
| 262 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 263 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | CODA_FREE(inp, insize); |
| 266 | return error; |
| 267 | } |
| 268 | |
| 269 | int venus_create(struct super_block *sb, struct CodaFid *dirfid, |
| 270 | const char *name, int length, int excl, int mode, |
| 271 | struct CodaFid *newfid, struct coda_vattr *attrs) |
| 272 | { |
| 273 | union inputArgs *inp; |
| 274 | union outputArgs *outp; |
| 275 | int insize, outsize, error; |
| 276 | int offset; |
| 277 | |
| 278 | offset = INSIZE(create); |
| 279 | insize = max_t(unsigned int, offset + length + 1, OUTSIZE(create)); |
| 280 | UPARG(CODA_CREATE); |
| 281 | |
| 282 | inp->coda_create.VFid = *dirfid; |
| 283 | inp->coda_create.attr.va_mode = mode; |
| 284 | inp->coda_create.excl = excl; |
| 285 | inp->coda_create.mode = mode; |
| 286 | inp->coda_create.name = offset; |
| 287 | |
| 288 | /* Venus must get null terminated string */ |
| 289 | memcpy((char *)(inp) + offset, name, length); |
| 290 | *((char *)inp + offset + length) = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 292 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 293 | if (!error) { |
| 294 | *attrs = outp->coda_create.attr; |
| 295 | *newfid = outp->coda_create.VFid; |
| 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | CODA_FREE(inp, insize); |
| 299 | return error; |
| 300 | } |
| 301 | |
| 302 | int venus_rmdir(struct super_block *sb, struct CodaFid *dirfid, |
| 303 | const char *name, int length) |
| 304 | { |
| 305 | union inputArgs *inp; |
| 306 | union outputArgs *outp; |
| 307 | int insize, outsize, error; |
| 308 | int offset; |
| 309 | |
| 310 | offset = INSIZE(rmdir); |
| 311 | insize = max_t(unsigned int, offset + length + 1, OUTSIZE(rmdir)); |
| 312 | UPARG(CODA_RMDIR); |
| 313 | |
| 314 | inp->coda_rmdir.VFid = *dirfid; |
| 315 | inp->coda_rmdir.name = offset; |
| 316 | memcpy((char *)(inp) + offset, name, length); |
| 317 | *((char *)inp + offset + length) = '\0'; |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 318 | |
| 319 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | CODA_FREE(inp, insize); |
| 322 | return error; |
| 323 | } |
| 324 | |
| 325 | int venus_remove(struct super_block *sb, struct CodaFid *dirfid, |
| 326 | const char *name, int length) |
| 327 | { |
| 328 | union inputArgs *inp; |
| 329 | union outputArgs *outp; |
| 330 | int error=0, insize, outsize, offset; |
| 331 | |
| 332 | offset = INSIZE(remove); |
| 333 | insize = max_t(unsigned int, offset + length + 1, OUTSIZE(remove)); |
| 334 | UPARG(CODA_REMOVE); |
| 335 | |
| 336 | inp->coda_remove.VFid = *dirfid; |
| 337 | inp->coda_remove.name = offset; |
| 338 | memcpy((char *)(inp) + offset, name, length); |
| 339 | *((char *)inp + offset + length) = '\0'; |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 340 | |
| 341 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | CODA_FREE(inp, insize); |
| 344 | return error; |
| 345 | } |
| 346 | |
| 347 | int venus_readlink(struct super_block *sb, struct CodaFid *fid, |
| 348 | char *buffer, int *length) |
| 349 | { |
| 350 | union inputArgs *inp; |
| 351 | union outputArgs *outp; |
| 352 | int insize, outsize, error; |
| 353 | int retlen; |
| 354 | char *result; |
| 355 | |
| 356 | insize = max_t(unsigned int, |
| 357 | INSIZE(readlink), OUTSIZE(readlink)+ *length + 1); |
| 358 | UPARG(CODA_READLINK); |
| 359 | |
| 360 | inp->coda_readlink.VFid = *fid; |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 361 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 362 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 363 | if (!error) { |
| 364 | retlen = outp->coda_readlink.count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if ( retlen > *length ) |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 366 | retlen = *length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | *length = retlen; |
| 368 | result = (char *)outp + (long)outp->coda_readlink.data; |
| 369 | memcpy(buffer, result, retlen); |
| 370 | *(buffer + retlen) = '\0'; |
| 371 | } |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | CODA_FREE(inp, insize); |
| 374 | return error; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | int venus_link(struct super_block *sb, struct CodaFid *fid, |
| 380 | struct CodaFid *dirfid, const char *name, int len ) |
| 381 | { |
| 382 | union inputArgs *inp; |
| 383 | union outputArgs *outp; |
| 384 | int insize, outsize, error; |
| 385 | int offset; |
| 386 | |
| 387 | offset = INSIZE(link); |
| 388 | insize = max_t(unsigned int, offset + len + 1, OUTSIZE(link)); |
| 389 | UPARG(CODA_LINK); |
| 390 | |
| 391 | inp->coda_link.sourceFid = *fid; |
| 392 | inp->coda_link.destFid = *dirfid; |
| 393 | inp->coda_link.tname = offset; |
| 394 | |
| 395 | /* make sure strings are null terminated */ |
| 396 | memcpy((char *)(inp) + offset, name, len); |
| 397 | *((char *)inp + offset + len) = '\0'; |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 398 | |
| 399 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | CODA_FREE(inp, insize); |
| 402 | return error; |
| 403 | } |
| 404 | |
| 405 | int venus_symlink(struct super_block *sb, struct CodaFid *fid, |
| 406 | const char *name, int len, |
| 407 | const char *symname, int symlen) |
| 408 | { |
| 409 | union inputArgs *inp; |
| 410 | union outputArgs *outp; |
| 411 | int insize, outsize, error; |
| 412 | int offset, s; |
| 413 | |
| 414 | offset = INSIZE(symlink); |
| 415 | insize = max_t(unsigned int, offset + len + symlen + 8, OUTSIZE(symlink)); |
| 416 | UPARG(CODA_SYMLINK); |
| 417 | |
| 418 | /* inp->coda_symlink.attr = *tva; XXXXXX */ |
| 419 | inp->coda_symlink.VFid = *fid; |
| 420 | |
| 421 | /* Round up to word boundary and null terminate */ |
| 422 | inp->coda_symlink.srcname = offset; |
| 423 | s = ( symlen & ~0x3 ) + 4; |
| 424 | memcpy((char *)(inp) + offset, symname, symlen); |
| 425 | *((char *)inp + offset + symlen) = '\0'; |
| 426 | |
| 427 | /* Round up to word boundary and null terminate */ |
| 428 | offset += s; |
| 429 | inp->coda_symlink.tname = offset; |
| 430 | s = (len & ~0x3) + 4; |
| 431 | memcpy((char *)(inp) + offset, name, len); |
| 432 | *((char *)inp + offset + len) = '\0'; |
| 433 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 434 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | CODA_FREE(inp, insize); |
| 437 | return error; |
| 438 | } |
| 439 | |
| 440 | int venus_fsync(struct super_block *sb, struct CodaFid *fid) |
| 441 | { |
| 442 | union inputArgs *inp; |
| 443 | union outputArgs *outp; |
| 444 | int insize, outsize, error; |
| 445 | |
| 446 | insize=SIZE(fsync); |
| 447 | UPARG(CODA_FSYNC); |
| 448 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 449 | inp->coda_fsync.VFid = *fid; |
| 450 | error = coda_upcall(coda_vcp(sb), sizeof(union inputArgs), |
| 451 | &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | CODA_FREE(inp, insize); |
| 454 | return error; |
| 455 | } |
| 456 | |
| 457 | int venus_access(struct super_block *sb, struct CodaFid *fid, int mask) |
| 458 | { |
| 459 | union inputArgs *inp; |
| 460 | union outputArgs *outp; |
| 461 | int insize, outsize, error; |
| 462 | |
| 463 | insize = SIZE(access); |
| 464 | UPARG(CODA_ACCESS); |
| 465 | |
| 466 | inp->coda_access.VFid = *fid; |
| 467 | inp->coda_access.flags = mask; |
| 468 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 469 | error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | CODA_FREE(inp, insize); |
| 472 | return error; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | int venus_pioctl(struct super_block *sb, struct CodaFid *fid, |
| 477 | unsigned int cmd, struct PioctlData *data) |
| 478 | { |
| 479 | union inputArgs *inp; |
| 480 | union outputArgs *outp; |
| 481 | int insize, outsize, error; |
| 482 | int iocsize; |
| 483 | |
| 484 | insize = VC_MAXMSGSIZE; |
| 485 | UPARG(CODA_IOCTL); |
| 486 | |
| 487 | /* build packet for Venus */ |
| 488 | if (data->vi.in_size > VC_MAXDATASIZE) { |
| 489 | error = -EINVAL; |
| 490 | goto exit; |
| 491 | } |
| 492 | |
| 493 | if (data->vi.out_size > VC_MAXDATASIZE) { |
| 494 | error = -EINVAL; |
| 495 | goto exit; |
| 496 | } |
| 497 | |
| 498 | inp->coda_ioctl.VFid = *fid; |
| 499 | |
| 500 | /* the cmd field was mutated by increasing its size field to |
| 501 | * reflect the path and follow args. We need to subtract that |
| 502 | * out before sending the command to Venus. */ |
| 503 | inp->coda_ioctl.cmd = (cmd & ~(PIOCPARM_MASK << 16)); |
| 504 | iocsize = ((cmd >> 16) & PIOCPARM_MASK) - sizeof(char *) - sizeof(int); |
| 505 | inp->coda_ioctl.cmd |= (iocsize & PIOCPARM_MASK) << 16; |
| 506 | |
| 507 | /* in->coda_ioctl.rwflag = flag; */ |
| 508 | inp->coda_ioctl.len = data->vi.in_size; |
| 509 | inp->coda_ioctl.data = (char *)(INSIZE(ioctl)); |
| 510 | |
| 511 | /* get the data out of user space */ |
| 512 | if ( copy_from_user((char*)inp + (long)inp->coda_ioctl.data, |
| 513 | data->vi.in, data->vi.in_size) ) { |
| 514 | error = -EINVAL; |
| 515 | goto exit; |
| 516 | } |
| 517 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 518 | error = coda_upcall(coda_vcp(sb), SIZE(ioctl) + data->vi.in_size, |
| 519 | &outsize, inp); |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if (error) { |
| 522 | printk("coda_pioctl: Venus returns: %d for %s\n", |
| 523 | error, coda_f2s(fid)); |
| 524 | goto exit; |
| 525 | } |
| 526 | |
| 527 | if (outsize < (long)outp->coda_ioctl.data + outp->coda_ioctl.len) { |
| 528 | error = -EINVAL; |
| 529 | goto exit; |
| 530 | } |
| 531 | |
| 532 | /* Copy out the OUT buffer. */ |
| 533 | if (outp->coda_ioctl.len > data->vi.out_size) { |
| 534 | error = -EINVAL; |
| 535 | goto exit; |
| 536 | } |
| 537 | |
| 538 | /* Copy out the OUT buffer. */ |
| 539 | if (copy_to_user(data->vi.out, |
| 540 | (char *)outp + (long)outp->coda_ioctl.data, |
| 541 | outp->coda_ioctl.len)) { |
| 542 | error = -EFAULT; |
| 543 | goto exit; |
| 544 | } |
| 545 | |
| 546 | exit: |
| 547 | CODA_FREE(inp, insize); |
| 548 | return error; |
| 549 | } |
| 550 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 551 | int venus_statfs(struct dentry *dentry, struct kstatfs *sfs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | { |
| 553 | union inputArgs *inp; |
| 554 | union outputArgs *outp; |
| 555 | int insize, outsize, error; |
| 556 | |
| 557 | insize = max_t(unsigned int, INSIZE(statfs), OUTSIZE(statfs)); |
| 558 | UPARG(CODA_STATFS); |
| 559 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 560 | error = coda_upcall(coda_vcp(dentry->d_sb), insize, &outsize, inp); |
Jan Harkes | 970648e | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 561 | if (!error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | sfs->f_blocks = outp->coda_statfs.stat.f_blocks; |
| 563 | sfs->f_bfree = outp->coda_statfs.stat.f_bfree; |
| 564 | sfs->f_bavail = outp->coda_statfs.stat.f_bavail; |
| 565 | sfs->f_files = outp->coda_statfs.stat.f_files; |
| 566 | sfs->f_ffree = outp->coda_statfs.stat.f_ffree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | CODA_FREE(inp, insize); |
| 570 | return error; |
| 571 | } |
| 572 | |
| 573 | /* |
| 574 | * coda_upcall and coda_downcall routines. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | */ |
Al Viro | 5f47c7e | 2007-07-20 00:23:31 +0100 | [diff] [blame] | 576 | static void coda_block_signals(sigset_t *old) |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 577 | { |
| 578 | spin_lock_irq(¤t->sighand->siglock); |
| 579 | *old = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 581 | sigfillset(¤t->blocked); |
| 582 | sigdelset(¤t->blocked, SIGKILL); |
| 583 | sigdelset(¤t->blocked, SIGSTOP); |
| 584 | sigdelset(¤t->blocked, SIGINT); |
| 585 | |
| 586 | recalc_sigpending(); |
| 587 | spin_unlock_irq(¤t->sighand->siglock); |
| 588 | } |
| 589 | |
Al Viro | 5f47c7e | 2007-07-20 00:23:31 +0100 | [diff] [blame] | 590 | static void coda_unblock_signals(sigset_t *old) |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 591 | { |
| 592 | spin_lock_irq(¤t->sighand->siglock); |
| 593 | current->blocked = *old; |
| 594 | recalc_sigpending(); |
| 595 | spin_unlock_irq(¤t->sighand->siglock); |
| 596 | } |
| 597 | |
| 598 | /* Don't allow signals to interrupt the following upcalls before venus |
| 599 | * has seen them, |
| 600 | * - CODA_CLOSE or CODA_RELEASE upcall (to avoid reference count problems) |
| 601 | * - CODA_STORE (to avoid data loss) |
| 602 | */ |
| 603 | #define CODA_INTERRUPTIBLE(r) (!coda_hard && \ |
| 604 | (((r)->uc_opcode != CODA_CLOSE && \ |
| 605 | (r)->uc_opcode != CODA_STORE && \ |
| 606 | (r)->uc_opcode != CODA_RELEASE) || \ |
| 607 | (r)->uc_flags & REQ_READ)) |
| 608 | |
| 609 | static inline void coda_waitfor_upcall(struct upc_req *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | DECLARE_WAITQUEUE(wait, current); |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 612 | unsigned long timeout = jiffies + coda_timeout * HZ; |
| 613 | sigset_t old; |
| 614 | int blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Al Viro | 5f47c7e | 2007-07-20 00:23:31 +0100 | [diff] [blame] | 616 | coda_block_signals(&old); |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 617 | blocked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 619 | add_wait_queue(&req->uc_sleep, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | for (;;) { |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 621 | if (CODA_INTERRUPTIBLE(req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | set_current_state(TASK_INTERRUPTIBLE); |
| 623 | else |
| 624 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* got a reply */ |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 627 | if (req->uc_flags & (REQ_WRITE | REQ_ABORT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | break; |
| 629 | |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 630 | if (blocked && time_after(jiffies, timeout) && |
| 631 | CODA_INTERRUPTIBLE(req)) |
| 632 | { |
Al Viro | 5f47c7e | 2007-07-20 00:23:31 +0100 | [diff] [blame] | 633 | coda_unblock_signals(&old); |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 634 | blocked = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 637 | if (signal_pending(current)) { |
| 638 | list_del(&req->uc_chain); |
| 639 | break; |
| 640 | } |
| 641 | |
| 642 | if (blocked) |
| 643 | schedule_timeout(HZ); |
| 644 | else |
| 645 | schedule(); |
| 646 | } |
| 647 | if (blocked) |
Al Viro | 5f47c7e | 2007-07-20 00:23:31 +0100 | [diff] [blame] | 648 | coda_unblock_signals(&old); |
Jan Harkes | d9664c9 | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 649 | |
| 650 | remove_wait_queue(&req->uc_sleep, &wait); |
| 651 | set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 655 | /* |
| 656 | * coda_upcall will return an error in the case of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | * failed communication with Venus _or_ will peek at Venus |
| 658 | * reply and return Venus' error. |
| 659 | * |
| 660 | * As venus has 2 types of errors, normal errors (positive) and internal |
| 661 | * errors (negative), normal errors are negated, while internal errors |
| 662 | * are all mapped to -EINTR, while showing a nice warning message. (jh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | */ |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 664 | static int coda_upcall(struct venus_comm *vcp, |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 665 | int inSize, int *outSize, |
| 666 | union inputArgs *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | union outputArgs *out; |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 669 | union inputArgs *sig_inputArgs; |
| 670 | struct upc_req *req, *sig_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | int error = 0; |
| 672 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 673 | if (!vcp->vc_inuse) { |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 674 | printk(KERN_NOTICE "coda: Venus dead, not sending upcall\n"); |
| 675 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /* Format the request message. */ |
Jan Harkes | 37461e1 | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 679 | req = kmalloc(sizeof(struct upc_req), GFP_KERNEL); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 680 | if (!req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return -ENOMEM; |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | req->uc_data = (void *)buffer; |
| 684 | req->uc_flags = 0; |
| 685 | req->uc_inSize = inSize; |
| 686 | req->uc_outSize = *outSize ? *outSize : inSize; |
| 687 | req->uc_opcode = ((union inputArgs *)buffer)->ih.opcode; |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 688 | req->uc_unique = ++vcp->vc_seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | init_waitqueue_head(&req->uc_sleep); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | /* Fill in the common input args. */ |
| 692 | ((union inputArgs *)buffer)->ih.unique = req->uc_unique; |
| 693 | |
| 694 | /* Append msg to pending queue and poke Venus. */ |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 695 | list_add_tail(&req->uc_chain, &vcp->vc_pending); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 696 | |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 697 | wake_up_interruptible(&vcp->vc_waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | /* We can be interrupted while we wait for Venus to process |
| 699 | * our request. If the interrupt occurs before Venus has read |
| 700 | * the request, we dequeue and return. If it occurs after the |
| 701 | * read but before the reply, we dequeue, send a signal |
| 702 | * message, and return. If it occurs after the reply we ignore |
| 703 | * it. In no case do we want to restart the syscall. If it |
| 704 | * was interrupted by a venus shutdown (psdev_close), return |
| 705 | * ENODEV. */ |
| 706 | |
| 707 | /* Go to sleep. Wake up on signals only after the timeout. */ |
Jan Harkes | 8706551 | 2007-07-19 01:48:45 -0700 | [diff] [blame] | 708 | coda_waitfor_upcall(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 710 | /* Op went through, interrupt or not... */ |
| 711 | if (req->uc_flags & REQ_WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | out = (union outputArgs *)req->uc_data; |
| 713 | /* here we map positive Venus errors to kernel errors */ |
| 714 | error = -out->oh.result; |
| 715 | *outSize = req->uc_outSize; |
| 716 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 719 | error = -EINTR; |
| 720 | if ((req->uc_flags & REQ_ABORT) || !signal_pending(current)) { |
| 721 | printk(KERN_WARNING "coda: Unexpected interruption.\n"); |
| 722 | goto exit; |
| 723 | } |
| 724 | |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 725 | /* Interrupted before venus read it. */ |
| 726 | if (!(req->uc_flags & REQ_READ)) |
| 727 | goto exit; |
| 728 | |
| 729 | /* Venus saw the upcall, make sure we can send interrupt signal */ |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 730 | if (!vcp->vc_inuse) { |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 731 | printk(KERN_INFO "coda: Venus dead, not sending signal.\n"); |
| 732 | goto exit; |
| 733 | } |
| 734 | |
| 735 | error = -ENOMEM; |
Jan Harkes | 37461e1 | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 736 | sig_req = kmalloc(sizeof(struct upc_req), GFP_KERNEL); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 737 | if (!sig_req) goto exit; |
| 738 | |
| 739 | CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); |
| 740 | if (!sig_req->uc_data) { |
Jan Harkes | 37461e1 | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 741 | kfree(sig_req); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 742 | goto exit; |
| 743 | } |
| 744 | |
| 745 | error = -EINTR; |
| 746 | sig_inputArgs = (union inputArgs *)sig_req->uc_data; |
| 747 | sig_inputArgs->ih.opcode = CODA_SIGNAL; |
| 748 | sig_inputArgs->ih.unique = req->uc_unique; |
| 749 | |
| 750 | sig_req->uc_flags = REQ_ASYNC; |
| 751 | sig_req->uc_opcode = sig_inputArgs->ih.opcode; |
| 752 | sig_req->uc_unique = sig_inputArgs->ih.unique; |
| 753 | sig_req->uc_inSize = sizeof(struct coda_in_hdr); |
| 754 | sig_req->uc_outSize = sizeof(struct coda_in_hdr); |
| 755 | |
| 756 | /* insert at head of queue! */ |
Jan Harkes | a1b0aa8 | 2007-07-19 01:48:50 -0700 | [diff] [blame] | 757 | list_add(&(sig_req->uc_chain), &vcp->vc_pending); |
| 758 | wake_up_interruptible(&vcp->vc_waitq); |
Jan Harkes | fe71b5f | 2007-07-19 01:48:46 -0700 | [diff] [blame] | 759 | |
| 760 | exit: |
Jan Harkes | 37461e1 | 2007-07-19 01:48:48 -0700 | [diff] [blame] | 761 | kfree(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | return error; |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | The statements below are part of the Coda opportunistic |
| 767 | programming -- taken from the Mach/BSD kernel code for Coda. |
| 768 | You don't get correct semantics by stating what needs to be |
| 769 | done without guaranteeing the invariants needed for it to happen. |
| 770 | When will be have time to find out what exactly is going on? (pjb) |
| 771 | */ |
| 772 | |
| 773 | |
| 774 | /* |
| 775 | * There are 7 cases where cache invalidations occur. The semantics |
| 776 | * of each is listed here: |
| 777 | * |
| 778 | * CODA_FLUSH -- flush all entries from the name cache and the cnode cache. |
| 779 | * CODA_PURGEUSER -- flush all entries from the name cache for a specific user |
| 780 | * This call is a result of token expiration. |
| 781 | * |
| 782 | * The next arise as the result of callbacks on a file or directory. |
| 783 | * CODA_ZAPFILE -- flush the cached attributes for a file. |
| 784 | |
| 785 | * CODA_ZAPDIR -- flush the attributes for the dir and |
| 786 | * force a new lookup for all the children |
| 787 | of this dir. |
| 788 | |
| 789 | * |
| 790 | * The next is a result of Venus detecting an inconsistent file. |
| 791 | * CODA_PURGEFID -- flush the attribute for the file |
| 792 | * purge it and its children from the dcache |
| 793 | * |
| 794 | * The last allows Venus to replace local fids with global ones |
| 795 | * during reintegration. |
| 796 | * |
| 797 | * CODA_REPLACE -- replace one CodaFid with another throughout the name cache */ |
| 798 | |
| 799 | int coda_downcall(int opcode, union outputArgs * out, struct super_block *sb) |
| 800 | { |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 801 | struct inode *inode = NULL; |
| 802 | struct CodaFid *fid, *newfid; |
| 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | /* Handle invalidation requests. */ |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 805 | if ( !sb || !sb->s_root) |
| 806 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 808 | switch (opcode) { |
| 809 | case CODA_FLUSH: |
| 810 | coda_cache_clear_all(sb); |
| 811 | shrink_dcache_sb(sb); |
| 812 | if (sb->s_root->d_inode) |
| 813 | coda_flag_inode(sb->s_root->d_inode, C_FLUSH); |
| 814 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 816 | case CODA_PURGEUSER: |
| 817 | coda_cache_clear_all(sb); |
| 818 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 820 | case CODA_ZAPDIR: |
| 821 | fid = &out->coda_zapdir.CodaFid; |
| 822 | inode = coda_fid_to_inode(fid, sb); |
| 823 | if (inode) { |
| 824 | coda_flag_inode_children(inode, C_PURGE); |
| 825 | coda_flag_inode(inode, C_VATTR); |
| 826 | } |
| 827 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 829 | case CODA_ZAPFILE: |
| 830 | fid = &out->coda_zapfile.CodaFid; |
| 831 | inode = coda_fid_to_inode(fid, sb); |
| 832 | if (inode) |
| 833 | coda_flag_inode(inode, C_VATTR); |
| 834 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 836 | case CODA_PURGEFID: |
| 837 | fid = &out->coda_purgefid.CodaFid; |
| 838 | inode = coda_fid_to_inode(fid, sb); |
| 839 | if (inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | coda_flag_inode_children(inode, C_PURGE); |
| 841 | |
| 842 | /* catch the dentries later if some are still busy */ |
| 843 | coda_flag_inode(inode, C_PURGE); |
| 844 | d_prune_aliases(inode); |
| 845 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 846 | } |
| 847 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Jan Harkes | 5fd31e9 | 2007-07-19 01:48:49 -0700 | [diff] [blame] | 849 | case CODA_REPLACE: |
| 850 | fid = &out->coda_replace.OldFid; |
| 851 | newfid = &out->coda_replace.NewFid; |
| 852 | inode = coda_fid_to_inode(fid, sb); |
| 853 | if (inode) |
| 854 | coda_replace_fid(inode, fid, newfid); |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | if (inode) |
| 859 | iput(inode); |
| 860 | |
| 861 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | |