9p.c (2e53160fc62d4d59c76bf93c7a90bd739b8b8157) | 9p.c (feabd6cf78ca3b57da2ce48e95b704e72147bf2c) |
---|---|
1/* 2 * Virtio 9p backend 3 * 4 * Copyright IBM, Corp. 2010 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * --- 246 unchanged lines hidden (view full) --- 255} 256 257static V9fsFidState *coroutine_fn get_fid(V9fsPDU *pdu, int32_t fid) 258{ 259 int err; 260 V9fsFidState *f; 261 V9fsState *s = pdu->s; 262 | 1/* 2 * Virtio 9p backend 3 * 4 * Copyright IBM, Corp. 2010 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * --- 246 unchanged lines hidden (view full) --- 255} 256 257static V9fsFidState *coroutine_fn get_fid(V9fsPDU *pdu, int32_t fid) 258{ 259 int err; 260 V9fsFidState *f; 261 V9fsState *s = pdu->s; 262 |
263 for (f = s->fid_list; f; f = f->next) { | 263 QSIMPLEQ_FOREACH(f, &s->fid_list, next) { |
264 BUG_ON(f->clunked); 265 if (f->fid == fid) { 266 /* 267 * Update the fid ref upfront so that 268 * we don't get reclaimed when we yield 269 * in open later. 270 */ 271 f->ref++; --- 18 unchanged lines hidden (view full) --- 290 } 291 return NULL; 292} 293 294static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) 295{ 296 V9fsFidState *f; 297 | 264 BUG_ON(f->clunked); 265 if (f->fid == fid) { 266 /* 267 * Update the fid ref upfront so that 268 * we don't get reclaimed when we yield 269 * in open later. 270 */ 271 f->ref++; --- 18 unchanged lines hidden (view full) --- 290 } 291 return NULL; 292} 293 294static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) 295{ 296 V9fsFidState *f; 297 |
298 for (f = s->fid_list; f; f = f->next) { | 298 QSIMPLEQ_FOREACH(f, &s->fid_list, next) { |
299 /* If fid is already there return NULL */ 300 BUG_ON(f->clunked); 301 if (f->fid == fid) { 302 return NULL; 303 } 304 } 305 f = g_malloc0(sizeof(V9fsFidState)); 306 f->fid = fid; 307 f->fid_type = P9_FID_NONE; 308 f->ref = 1; 309 /* 310 * Mark the fid as referenced so that the LRU 311 * reclaim won't close the file descriptor 312 */ 313 f->flags |= FID_REFERENCED; | 299 /* If fid is already there return NULL */ 300 BUG_ON(f->clunked); 301 if (f->fid == fid) { 302 return NULL; 303 } 304 } 305 f = g_malloc0(sizeof(V9fsFidState)); 306 f->fid = fid; 307 f->fid_type = P9_FID_NONE; 308 f->ref = 1; 309 /* 310 * Mark the fid as referenced so that the LRU 311 * reclaim won't close the file descriptor 312 */ 313 f->flags |= FID_REFERENCED; |
314 f->next = s->fid_list; 315 s->fid_list = f; | 314 QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next); |
316 317 v9fs_readdir_init(s->proto_version, &f->fs.dir); 318 v9fs_readdir_init(s->proto_version, &f->fs_reclaim.dir); 319 320 return f; 321} 322 323static int coroutine_fn v9fs_xattr_fid_clunk(V9fsPDU *pdu, V9fsFidState *fidp) --- 72 unchanged lines hidden (view full) --- 396 } 397 return free_fid(pdu, fidp); 398 } 399 return 0; 400} 401 402static V9fsFidState *clunk_fid(V9fsState *s, int32_t fid) 403{ | 315 316 v9fs_readdir_init(s->proto_version, &f->fs.dir); 317 v9fs_readdir_init(s->proto_version, &f->fs_reclaim.dir); 318 319 return f; 320} 321 322static int coroutine_fn v9fs_xattr_fid_clunk(V9fsPDU *pdu, V9fsFidState *fidp) --- 72 unchanged lines hidden (view full) --- 395 } 396 return free_fid(pdu, fidp); 397 } 398 return 0; 399} 400 401static V9fsFidState *clunk_fid(V9fsState *s, int32_t fid) 402{ |
404 V9fsFidState **fidpp, *fidp; | 403 V9fsFidState *fidp; |
405 | 404 |
406 for (fidpp = &s->fid_list; *fidpp; fidpp = &(*fidpp)->next) { 407 if ((*fidpp)->fid == fid) { 408 break; | 405 QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { 406 if (fidp->fid == fid) { 407 QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); 408 fidp->clunked = true; 409 return fidp; |
409 } 410 } | 410 } 411 } |
411 if (*fidpp == NULL) { 412 return NULL; 413 } 414 fidp = *fidpp; 415 *fidpp = fidp->next; 416 fidp->clunked = true; 417 return fidp; | 412 return NULL; |
418} 419 420void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) 421{ 422 int reclaim_count = 0; 423 V9fsState *s = pdu->s; 424 V9fsFidState *f, *reclaim_list = NULL; 425 | 413} 414 415void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) 416{ 417 int reclaim_count = 0; 418 V9fsState *s = pdu->s; 419 V9fsFidState *f, *reclaim_list = NULL; 420 |
426 for (f = s->fid_list; f; f = f->next) { | 421 QSIMPLEQ_FOREACH(f, &s->fid_list, next) { |
427 /* 428 * Unlink fids cannot be reclaimed. Check 429 * for them and skip them. Also skip fids 430 * currently being operated on. 431 */ 432 if (f->ref || f->flags & FID_NON_RECLAIMABLE) { 433 continue; 434 } --- 65 unchanged lines hidden (view full) --- 500 501static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) 502{ 503 int err; 504 V9fsState *s = pdu->s; 505 V9fsFidState *fidp; 506 507again: | 422 /* 423 * Unlink fids cannot be reclaimed. Check 424 * for them and skip them. Also skip fids 425 * currently being operated on. 426 */ 427 if (f->ref || f->flags & FID_NON_RECLAIMABLE) { 428 continue; 429 } --- 65 unchanged lines hidden (view full) --- 495 496static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) 497{ 498 int err; 499 V9fsState *s = pdu->s; 500 V9fsFidState *fidp; 501 502again: |
508 for (fidp = s->fid_list; fidp; fidp = fidp->next) { | 503 QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { |
509 if (fidp->path.size != path->size) { 510 continue; 511 } 512 if (!memcmp(fidp->path.data, path->data, path->size)) { 513 /* Mark the fid non reclaimable. */ 514 fidp->flags |= FID_NON_RECLAIMABLE; 515 516 /* reopen the file/dir if already closed */ --- 15 unchanged lines hidden (view full) --- 532} 533 534static void coroutine_fn virtfs_reset(V9fsPDU *pdu) 535{ 536 V9fsState *s = pdu->s; 537 V9fsFidState *fidp; 538 539 /* Free all fids */ | 504 if (fidp->path.size != path->size) { 505 continue; 506 } 507 if (!memcmp(fidp->path.data, path->data, path->size)) { 508 /* Mark the fid non reclaimable. */ 509 fidp->flags |= FID_NON_RECLAIMABLE; 510 511 /* reopen the file/dir if already closed */ --- 15 unchanged lines hidden (view full) --- 527} 528 529static void coroutine_fn virtfs_reset(V9fsPDU *pdu) 530{ 531 V9fsState *s = pdu->s; 532 V9fsFidState *fidp; 533 534 /* Free all fids */ |
540 while (s->fid_list) { | 535 while (!QSIMPLEQ_EMPTY(&s->fid_list)) { |
541 /* Get fid */ | 536 /* Get fid */ |
542 fidp = s->fid_list; | 537 fidp = QSIMPLEQ_FIRST(&s->fid_list); |
543 fidp->ref++; 544 545 /* Clunk fid */ | 538 fidp->ref++; 539 540 /* Clunk fid */ |
546 s->fid_list = fidp->next; | 541 QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); |
547 fidp->clunked = true; 548 549 put_fid(pdu, fidp); 550 } 551} 552 553#define P9_QID_TYPE_DIR 0x80 554#define P9_QID_TYPE_SYMLINK 0x02 --- 2561 unchanged lines hidden (view full) --- 3116 err = v9fs_co_rename(pdu, &fidp->path, &new_path); 3117 if (err < 0) { 3118 goto out; 3119 } 3120 /* 3121 * Fixup fid's pointing to the old name to 3122 * start pointing to the new name 3123 */ | 542 fidp->clunked = true; 543 544 put_fid(pdu, fidp); 545 } 546} 547 548#define P9_QID_TYPE_DIR 0x80 549#define P9_QID_TYPE_SYMLINK 0x02 --- 2561 unchanged lines hidden (view full) --- 3111 err = v9fs_co_rename(pdu, &fidp->path, &new_path); 3112 if (err < 0) { 3113 goto out; 3114 } 3115 /* 3116 * Fixup fid's pointing to the old name to 3117 * start pointing to the new name 3118 */ |
3124 for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { | 3119 QSIMPLEQ_FOREACH(tfidp, &s->fid_list, next) { |
3125 if (v9fs_path_is_ancestor(&fidp->path, &tfidp->path)) { 3126 /* replace the name */ 3127 v9fs_fix_path(&tfidp->path, &new_path, strlen(fidp->path.data)); 3128 } 3129 } 3130out: 3131 if (dirfidp) { 3132 put_fid(pdu, dirfidp); --- 77 unchanged lines hidden (view full) --- 3210 if (err < 0) { 3211 goto out; 3212 } 3213 3214 /* 3215 * Fixup fid's pointing to the old name to 3216 * start pointing to the new name 3217 */ | 3120 if (v9fs_path_is_ancestor(&fidp->path, &tfidp->path)) { 3121 /* replace the name */ 3122 v9fs_fix_path(&tfidp->path, &new_path, strlen(fidp->path.data)); 3123 } 3124 } 3125out: 3126 if (dirfidp) { 3127 put_fid(pdu, dirfidp); --- 77 unchanged lines hidden (view full) --- 3205 if (err < 0) { 3206 goto out; 3207 } 3208 3209 /* 3210 * Fixup fid's pointing to the old name to 3211 * start pointing to the new name 3212 */ |
3218 for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { | 3213 QSIMPLEQ_FOREACH(tfidp, &s->fid_list, next) { |
3219 if (v9fs_path_is_ancestor(&oldpath, &tfidp->path)) { 3220 /* replace the name */ 3221 v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); 3222 } 3223 } 3224out: 3225 v9fs_path_free(&oldpath); 3226 v9fs_path_free(&newpath); --- 849 unchanged lines hidden (view full) --- 4076 s->tag = g_strdup(s->fsconf.tag); 4077 s->ctx.uid = -1; 4078 4079 s->ops = fse->ops; 4080 4081 s->ctx.fmode = fse->fmode; 4082 s->ctx.dmode = fse->dmode; 4083 | 3214 if (v9fs_path_is_ancestor(&oldpath, &tfidp->path)) { 3215 /* replace the name */ 3216 v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); 3217 } 3218 } 3219out: 3220 v9fs_path_free(&oldpath); 3221 v9fs_path_free(&newpath); --- 849 unchanged lines hidden (view full) --- 4071 s->tag = g_strdup(s->fsconf.tag); 4072 s->ctx.uid = -1; 4073 4074 s->ops = fse->ops; 4075 4076 s->ctx.fmode = fse->fmode; 4077 s->ctx.dmode = fse->dmode; 4078 |
4084 s->fid_list = NULL; | 4079 QSIMPLEQ_INIT(&s->fid_list); |
4085 qemu_co_rwlock_init(&s->rename_lock); 4086 4087 if (s->ops->init(&s->ctx, errp) < 0) { 4088 error_prepend(errp, "cannot initialize fsdev '%s': ", 4089 s->fsconf.fsdev_id); 4090 goto out; 4091 } 4092 --- 98 unchanged lines hidden --- | 4080 qemu_co_rwlock_init(&s->rename_lock); 4081 4082 if (s->ops->init(&s->ctx, errp) < 0) { 4083 error_prepend(errp, "cannot initialize fsdev '%s': ", 4084 s->fsconf.fsdev_id); 4085 goto out; 4086 } 4087 --- 98 unchanged lines hidden --- |