diff options
author | Jeff Layton <jlayton@redhat.com> | 2010-10-15 15:33:59 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2010-10-17 21:04:19 -0400 |
commit | 15886177e412db00aa86155fe72608c4ebf5a08f (patch) | |
tree | eb4ac34ee40ae499ae2a68c44f71effe657b4504 /fs/cifs | |
parent | abfe1eedd682ea0f20e7035445982e6d371a2024 (diff) |
cifs: clean up cifs_reopen_file
Add a f_flags field that holds the f_flags field from the filp. We'll
need this info in case the filp ever goes away before the cifsFileInfo
does. Have cifs_reopen_file use that value instead of filp->f_flags
too and have it take a cifsFileInfo arg instead of a filp.
While we're at it, get rid of some bogus cargo-cult NULL pointer
checks in that function and reduce the level of indentation.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Suresh Jayaraman <sjayaraman@suse.de>
Acked-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs')
-rw-r--r-- | fs/cifs/cifsglob.h | 1 | ||||
-rw-r--r-- | fs/cifs/dir.c | 1 | ||||
-rw-r--r-- | fs/cifs/file.c | 129 |
3 files changed, 57 insertions, 74 deletions
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 6c69bd762498..b746dec88396 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -390,6 +390,7 @@ struct cifsFileInfo { | |||
390 | /* lock scope id (0 if none) */ | 390 | /* lock scope id (0 if none) */ |
391 | struct file *pfile; /* needed for writepage */ | 391 | struct file *pfile; /* needed for writepage */ |
392 | struct dentry *dentry; | 392 | struct dentry *dentry; |
393 | unsigned int f_flags; | ||
393 | struct tcon_link *tlink; | 394 | struct tcon_link *tlink; |
394 | struct mutex lock_mutex; | 395 | struct mutex lock_mutex; |
395 | struct list_head llist; /* list of byte range locks we have. */ | 396 | struct list_head llist; /* list of byte range locks we have. */ |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 36cf3e2ec252..3c23d882a44c 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -147,6 +147,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, | |||
147 | pCifsFile->pid = current->tgid; | 147 | pCifsFile->pid = current->tgid; |
148 | pCifsFile->uid = current_fsuid(); | 148 | pCifsFile->uid = current_fsuid(); |
149 | pCifsFile->dentry = dget(dentry); | 149 | pCifsFile->dentry = dget(dentry); |
150 | pCifsFile->f_flags = file->f_flags; | ||
150 | pCifsFile->pfile = file; | 151 | pCifsFile->pfile = file; |
151 | pCifsFile->invalidHandle = false; | 152 | pCifsFile->invalidHandle = false; |
152 | pCifsFile->closePend = false; | 153 | pCifsFile->closePend = false; |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 394cf28f080d..dd922a5f9cae 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -412,14 +412,13 @@ static int cifs_relock_file(struct cifsFileInfo *cifsFile) | |||
412 | return rc; | 412 | return rc; |
413 | } | 413 | } |
414 | 414 | ||
415 | static int cifs_reopen_file(struct file *file, bool can_flush) | 415 | static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) |
416 | { | 416 | { |
417 | int rc = -EACCES; | 417 | int rc = -EACCES; |
418 | int xid; | 418 | int xid; |
419 | __u32 oplock; | 419 | __u32 oplock; |
420 | struct cifs_sb_info *cifs_sb; | 420 | struct cifs_sb_info *cifs_sb; |
421 | struct cifsTconInfo *tcon; | 421 | struct cifsTconInfo *tcon; |
422 | struct cifsFileInfo *pCifsFile; | ||
423 | struct cifsInodeInfo *pCifsInode; | 422 | struct cifsInodeInfo *pCifsInode; |
424 | struct inode *inode; | 423 | struct inode *inode; |
425 | char *full_path = NULL; | 424 | char *full_path = NULL; |
@@ -427,11 +426,6 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
427 | int disposition = FILE_OPEN; | 426 | int disposition = FILE_OPEN; |
428 | __u16 netfid; | 427 | __u16 netfid; |
429 | 428 | ||
430 | if (file->private_data) | ||
431 | pCifsFile = file->private_data; | ||
432 | else | ||
433 | return -EBADF; | ||
434 | |||
435 | xid = GetXid(); | 429 | xid = GetXid(); |
436 | mutex_lock(&pCifsFile->fh_mutex); | 430 | mutex_lock(&pCifsFile->fh_mutex); |
437 | if (!pCifsFile->invalidHandle) { | 431 | if (!pCifsFile->invalidHandle) { |
@@ -441,21 +435,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
441 | return rc; | 435 | return rc; |
442 | } | 436 | } |
443 | 437 | ||
444 | if (file->f_path.dentry == NULL) { | 438 | inode = pCifsFile->dentry->d_inode; |
445 | cERROR(1, "no valid name if dentry freed"); | ||
446 | dump_stack(); | ||
447 | rc = -EBADF; | ||
448 | goto reopen_error_exit; | ||
449 | } | ||
450 | |||
451 | inode = file->f_path.dentry->d_inode; | ||
452 | if (inode == NULL) { | ||
453 | cERROR(1, "inode not valid"); | ||
454 | dump_stack(); | ||
455 | rc = -EBADF; | ||
456 | goto reopen_error_exit; | ||
457 | } | ||
458 | |||
459 | cifs_sb = CIFS_SB(inode->i_sb); | 439 | cifs_sb = CIFS_SB(inode->i_sb); |
460 | tcon = tlink_tcon(pCifsFile->tlink); | 440 | tcon = tlink_tcon(pCifsFile->tlink); |
461 | 441 | ||
@@ -463,17 +443,16 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
463 | those that already have the rename sem can end up causing writepage | 443 | those that already have the rename sem can end up causing writepage |
464 | to get called and if the server was down that means we end up here, | 444 | to get called and if the server was down that means we end up here, |
465 | and we can never tell if the caller already has the rename_sem */ | 445 | and we can never tell if the caller already has the rename_sem */ |
466 | full_path = build_path_from_dentry(file->f_path.dentry); | 446 | full_path = build_path_from_dentry(pCifsFile->dentry); |
467 | if (full_path == NULL) { | 447 | if (full_path == NULL) { |
468 | rc = -ENOMEM; | 448 | rc = -ENOMEM; |
469 | reopen_error_exit: | ||
470 | mutex_unlock(&pCifsFile->fh_mutex); | 449 | mutex_unlock(&pCifsFile->fh_mutex); |
471 | FreeXid(xid); | 450 | FreeXid(xid); |
472 | return rc; | 451 | return rc; |
473 | } | 452 | } |
474 | 453 | ||
475 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", | 454 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", |
476 | inode, file->f_flags, full_path); | 455 | inode, pCifsFile->f_flags, full_path); |
477 | 456 | ||
478 | if (oplockEnabled) | 457 | if (oplockEnabled) |
479 | oplock = REQ_OPLOCK; | 458 | oplock = REQ_OPLOCK; |
@@ -488,7 +467,8 @@ reopen_error_exit: | |||
488 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the | 467 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the |
489 | * original open. Must mask them off for a reopen. | 468 | * original open. Must mask them off for a reopen. |
490 | */ | 469 | */ |
491 | unsigned int oflags = file->f_flags & ~(O_CREAT|O_EXCL|O_TRUNC); | 470 | unsigned int oflags = pCifsFile->f_flags & |
471 | ~(O_CREAT | O_EXCL | O_TRUNC); | ||
492 | 472 | ||
493 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, | 473 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, |
494 | cifs_sb->mnt_file_mode /* ignored */, | 474 | cifs_sb->mnt_file_mode /* ignored */, |
@@ -501,7 +481,7 @@ reopen_error_exit: | |||
501 | in the reconnect path it is important to retry hard */ | 481 | in the reconnect path it is important to retry hard */ |
502 | } | 482 | } |
503 | 483 | ||
504 | desiredAccess = cifs_convert_flags(file->f_flags); | 484 | desiredAccess = cifs_convert_flags(pCifsFile->f_flags); |
505 | 485 | ||
506 | /* Can not refresh inode by passing in file_info buf to be returned | 486 | /* Can not refresh inode by passing in file_info buf to be returned |
507 | by SMBOpen and then calling get_inode_info with returned buf | 487 | by SMBOpen and then calling get_inode_info with returned buf |
@@ -517,49 +497,50 @@ reopen_error_exit: | |||
517 | mutex_unlock(&pCifsFile->fh_mutex); | 497 | mutex_unlock(&pCifsFile->fh_mutex); |
518 | cFYI(1, "cifs_open returned 0x%x", rc); | 498 | cFYI(1, "cifs_open returned 0x%x", rc); |
519 | cFYI(1, "oplock: %d", oplock); | 499 | cFYI(1, "oplock: %d", oplock); |
520 | } else { | 500 | goto reopen_error_exit; |
501 | } | ||
502 | |||
521 | reopen_success: | 503 | reopen_success: |
522 | pCifsFile->netfid = netfid; | 504 | pCifsFile->netfid = netfid; |
523 | pCifsFile->invalidHandle = false; | 505 | pCifsFile->invalidHandle = false; |
524 | mutex_unlock(&pCifsFile->fh_mutex); | 506 | mutex_unlock(&pCifsFile->fh_mutex); |
525 | pCifsInode = CIFS_I(inode); | 507 | pCifsInode = CIFS_I(inode); |
526 | if (pCifsInode) { | 508 | |
527 | if (can_flush) { | 509 | if (can_flush) { |
528 | rc = filemap_write_and_wait(inode->i_mapping); | 510 | rc = filemap_write_and_wait(inode->i_mapping); |
529 | if (rc != 0) | 511 | if (rc != 0) |
530 | CIFS_I(inode)->write_behind_rc = rc; | 512 | CIFS_I(inode)->write_behind_rc = rc; |
531 | /* temporarily disable caching while we | 513 | |
532 | go to server to get inode info */ | 514 | pCifsInode->clientCanCacheAll = false; |
533 | pCifsInode->clientCanCacheAll = false; | 515 | pCifsInode->clientCanCacheRead = false; |
534 | pCifsInode->clientCanCacheRead = false; | 516 | if (tcon->unix_ext) |
535 | if (tcon->unix_ext) | 517 | rc = cifs_get_inode_info_unix(&inode, |
536 | rc = cifs_get_inode_info_unix(&inode, | 518 | full_path, inode->i_sb, xid); |
537 | full_path, inode->i_sb, xid); | 519 | else |
538 | else | 520 | rc = cifs_get_inode_info(&inode, |
539 | rc = cifs_get_inode_info(&inode, | 521 | full_path, NULL, inode->i_sb, |
540 | full_path, NULL, inode->i_sb, | 522 | xid, NULL); |
541 | xid, NULL); | 523 | } /* else we are writing out data to server already |
542 | } /* else we are writing out data to server already | 524 | and could deadlock if we tried to flush data, and |
543 | and could deadlock if we tried to flush data, and | 525 | since we do not know if we have data that would |
544 | since we do not know if we have data that would | 526 | invalidate the current end of file on the server |
545 | invalidate the current end of file on the server | 527 | we can not go to the server to get the new inod |
546 | we can not go to the server to get the new inod | 528 | info */ |
547 | info */ | 529 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { |
548 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | 530 | pCifsInode->clientCanCacheAll = true; |
549 | pCifsInode->clientCanCacheAll = true; | 531 | pCifsInode->clientCanCacheRead = true; |
550 | pCifsInode->clientCanCacheRead = true; | 532 | cFYI(1, "Exclusive Oplock granted on inode %p", |
551 | cFYI(1, "Exclusive Oplock granted on inode %p", | 533 | pCifsFile->dentry->d_inode); |
552 | file->f_path.dentry->d_inode); | 534 | } else if ((oplock & 0xF) == OPLOCK_READ) { |
553 | } else if ((oplock & 0xF) == OPLOCK_READ) { | 535 | pCifsInode->clientCanCacheRead = true; |
554 | pCifsInode->clientCanCacheRead = true; | 536 | pCifsInode->clientCanCacheAll = false; |
555 | pCifsInode->clientCanCacheAll = false; | 537 | } else { |
556 | } else { | 538 | pCifsInode->clientCanCacheRead = false; |
557 | pCifsInode->clientCanCacheRead = false; | 539 | pCifsInode->clientCanCacheAll = false; |
558 | pCifsInode->clientCanCacheAll = false; | ||
559 | } | ||
560 | cifs_relock_file(pCifsFile); | ||
561 | } | ||
562 | } | 540 | } |
541 | cifs_relock_file(pCifsFile); | ||
542 | |||
543 | reopen_error_exit: | ||
563 | kfree(full_path); | 544 | kfree(full_path); |
564 | FreeXid(xid); | 545 | FreeXid(xid); |
565 | return rc; | 546 | return rc; |
@@ -998,7 +979,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, | |||
998 | filemap_fdatawait from here so tell | 979 | filemap_fdatawait from here so tell |
999 | reopen_file not to flush data to server | 980 | reopen_file not to flush data to server |
1000 | now */ | 981 | now */ |
1001 | rc = cifs_reopen_file(file, false); | 982 | rc = cifs_reopen_file(open_file, false); |
1002 | if (rc != 0) | 983 | if (rc != 0) |
1003 | break; | 984 | break; |
1004 | } | 985 | } |
@@ -1096,7 +1077,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data, | |||
1096 | filemap_fdatawait from here so tell | 1077 | filemap_fdatawait from here so tell |
1097 | reopen_file not to flush data to | 1078 | reopen_file not to flush data to |
1098 | server now */ | 1079 | server now */ |
1099 | rc = cifs_reopen_file(file, false); | 1080 | rc = cifs_reopen_file(open_file, false); |
1100 | if (rc != 0) | 1081 | if (rc != 0) |
1101 | break; | 1082 | break; |
1102 | } | 1083 | } |
@@ -1244,7 +1225,7 @@ refind_writable: | |||
1244 | 1225 | ||
1245 | read_unlock(&GlobalSMBSeslock); | 1226 | read_unlock(&GlobalSMBSeslock); |
1246 | /* Had to unlock since following call can block */ | 1227 | /* Had to unlock since following call can block */ |
1247 | rc = cifs_reopen_file(open_file->pfile, false); | 1228 | rc = cifs_reopen_file(open_file, false); |
1248 | if (!rc) { | 1229 | if (!rc) { |
1249 | if (!open_file->closePend) | 1230 | if (!open_file->closePend) |
1250 | return open_file; | 1231 | return open_file; |
@@ -1792,7 +1773,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data, | |||
1792 | int buf_type = CIFS_NO_BUFFER; | 1773 | int buf_type = CIFS_NO_BUFFER; |
1793 | if ((open_file->invalidHandle) && | 1774 | if ((open_file->invalidHandle) && |
1794 | (!open_file->closePend)) { | 1775 | (!open_file->closePend)) { |
1795 | rc = cifs_reopen_file(file, true); | 1776 | rc = cifs_reopen_file(open_file, true); |
1796 | if (rc != 0) | 1777 | if (rc != 0) |
1797 | break; | 1778 | break; |
1798 | } | 1779 | } |
@@ -1878,7 +1859,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
1878 | while (rc == -EAGAIN) { | 1859 | while (rc == -EAGAIN) { |
1879 | if ((open_file->invalidHandle) && | 1860 | if ((open_file->invalidHandle) && |
1880 | (!open_file->closePend)) { | 1861 | (!open_file->closePend)) { |
1881 | rc = cifs_reopen_file(file, true); | 1862 | rc = cifs_reopen_file(open_file, true); |
1882 | if (rc != 0) | 1863 | if (rc != 0) |
1883 | break; | 1864 | break; |
1884 | } | 1865 | } |
@@ -2043,7 +2024,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2043 | while (rc == -EAGAIN) { | 2024 | while (rc == -EAGAIN) { |
2044 | if ((open_file->invalidHandle) && | 2025 | if ((open_file->invalidHandle) && |
2045 | (!open_file->closePend)) { | 2026 | (!open_file->closePend)) { |
2046 | rc = cifs_reopen_file(file, true); | 2027 | rc = cifs_reopen_file(open_file, true); |
2047 | if (rc != 0) | 2028 | if (rc != 0) |
2048 | break; | 2029 | break; |
2049 | } | 2030 | } |