History

Merge git://git.samba.org/sfrench/cifs-2.6

* git://git.samba.org/sfrench/cifs-2.6: CIFS: Cleanup byte-range locking code style CIFS: Simplify setlk error handling for mandatory locking

Linus Torvalds committed 15 years ago

Commit ff4d7fa2 parents e0d6511 a88b4701 file · +50 −55Browse files

Unified · Split

fs/cifs/file.c+50−55
@@ -645,20 +645,20 @@ int cifs_closedir(struct inode *inode, struct file *file) · 644 unmodified lines
645645 }
646646
647647 static struct cifsLockInfo *
648−cifs_lock_init(__u64 len, __u64 offset, __u8 type, __u16 netfid)
648+cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
649649 {
650− struct cifsLockInfo *li =
650+ struct cifsLockInfo *lock =
651651 kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);
652− if (!li)
653− return li;
654− li->netfid = netfid;
655− li->offset = offset;
656− li->length = len;
657− li->type = type;
658− li->pid = current->tgid;
659− INIT_LIST_HEAD(&li->blist);
660− init_waitqueue_head(&li->block_q);
661− return li;
652+ if (!lock)
653+ return lock;
654+ lock->offset = offset;
655+ lock->length = length;
656+ lock->type = type;
657+ lock->netfid = netfid;
658+ lock->pid = current->tgid;
659+ INIT_LIST_HEAD(&lock->blist);
660+ init_waitqueue_head(&lock->block_q);
661+ return lock;
662662 }
663663
664664 static void
@@ -672,7 +672,7 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock) · 7 unmodified lines
672672 }
673673
674674 static bool
675−cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
675+__cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
676676 __u64 length, __u8 type, __u16 netfid,
677677 struct cifsLockInfo **conf_lock)
678678 {
@@ -694,6 +694,14 @@ cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset, · 15 unmodified lines
694694 return false;
695695 }
696696
697+static bool
698+cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
699+ struct cifsLockInfo **conf_lock)
700+{
701+ return __cifs_find_lock_conflict(cinode, lock->offset, lock->length,
702+ lock->type, lock->netfid, conf_lock);
703+}
704+
697705 static int
698706 cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
699707 __u8 type, __u16 netfid, struct file_lock *flock)
@@ -704,8 +712,8 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length, · 4 unmodified lines
704712
705713 mutex_lock(&cinode->lock_mutex);
706714
707− exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
708− &conf_lock);
715+ exist = __cifs_find_lock_conflict(cinode, offset, length, type, netfid,
716+ &conf_lock);
709717 if (exist) {
710718 flock->fl_start = conf_lock->offset;
711719 flock->fl_end = conf_lock->offset + conf_lock->length - 1;
@@ -723,40 +731,27 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length, · 11 unmodified lines
723731 return rc;
724732 }
725733
726−static int
727−cifs_lock_add(struct cifsInodeInfo *cinode, __u64 len, __u64 offset,
728− __u8 type, __u16 netfid)
734+static void
735+cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
729736 {
730− struct cifsLockInfo *li;
731−
732− li = cifs_lock_init(len, offset, type, netfid);
733− if (!li)
734− return -ENOMEM;
735−
736737 mutex_lock(&cinode->lock_mutex);
737− list_add_tail(&li->llist, &cinode->llist);
738+ list_add_tail(&lock->llist, &cinode->llist);
738739 mutex_unlock(&cinode->lock_mutex);
739− return 0;
740740 }
741741
742742 static int
743−cifs_lock_add_if(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
744− __u8 type, __u16 netfid, bool wait)
743+cifs_lock_add_if(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
744+ bool wait)
745745 {
746− struct cifsLockInfo *lock, *conf_lock;
746+ struct cifsLockInfo *conf_lock;
747747 bool exist;
748748 int rc = 0;
749749
750− lock = cifs_lock_init(length, offset, type, netfid);
751− if (!lock)
752− return -ENOMEM;
753−
754750 try_again:
755751 exist = false;
756752 mutex_lock(&cinode->lock_mutex);
757753
758− exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
759− &conf_lock);
754+ exist = cifs_find_lock_conflict(cinode, lock, &conf_lock);
760755 if (!exist && cinode->can_cache_brlcks) {
761756 list_add_tail(&lock->llist, &cinode->llist);
762757 mutex_unlock(&cinode->lock_mutex);
@@ -775,13 +770,10 @@ try_again: · 12 unmodified lines
775770 (lock->blist.next == &lock->blist));
776771 if (!rc)
777772 goto try_again;
778− else {
779− mutex_lock(&cinode->lock_mutex);
780− list_del_init(&lock->blist);
781− }
773+ mutex_lock(&cinode->lock_mutex);
774+ list_del_init(&lock->blist);
782775 }
783776
784− kfree(lock);
785777 mutex_unlock(&cinode->lock_mutex);
786778 return rc;
787779 }
@@ -933,7 +925,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) · 145 unmodified lines
933925 else
934926 type = CIFS_WRLCK;
935927
936− lck = cifs_lock_init(length, flock->fl_start, type,
928+ lck = cifs_lock_init(flock->fl_start, length, type,
937929 cfile->netfid);
938930 if (!lck) {
939931 rc = -ENOMEM;
@@ -1070,14 +1062,12 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type, · 130 unmodified lines
10701062 if (rc != 0)
10711063 cERROR(1, "Error unlocking previously locked "
10721064 "range %d during test of lock", rc);
1073− rc = 0;
1074− return rc;
1065+ return 0;
10751066 }
10761067
10771068 if (type & LOCKING_ANDX_SHARED_LOCK) {
10781069 flock->fl_type = F_WRLCK;
1079− rc = 0;
1080− return rc;
1070+ return 0;
10811071 }
10821072
10831073 rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
@@ -1095,8 +1085,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type, · 11 unmodified lines
10951085 } else
10961086 flock->fl_type = F_WRLCK;
10971087
1098− rc = 0;
1099− return rc;
1088+ return 0;
11001089 }
11011090
11021091 static void
@@ -1254,20 +1243,26 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u8 type, · 151 unmodified lines
12541243 }
12551244
12561245 if (lock) {
1257− rc = cifs_lock_add_if(cinode, flock->fl_start, length,
1258− type, netfid, wait_flag);
1246+ struct cifsLockInfo *lock;
1247+
1248+ lock = cifs_lock_init(flock->fl_start, length, type, netfid);
1249+ if (!lock)
1250+ return -ENOMEM;
1251+
1252+ rc = cifs_lock_add_if(cinode, lock, wait_flag);
12591253 if (rc < 0)
1260− return rc;
1261− else if (!rc)
1254+ kfree(lock);
1255+ if (rc <= 0)
12621256 goto out;
12631257
12641258 rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
12651259 flock->fl_start, 0, 1, type, wait_flag, 0);
1266− if (rc == 0) {
1267− /* For Windows locks we must store them. */
1268− rc = cifs_lock_add(cinode, length, flock->fl_start,
1269− type, netfid);
1260+ if (rc) {
1261+ kfree(lock);
1262+ goto out;
12701263 }
1264+
1265+ cifs_lock_add(cinode, lock);
12711266 } else if (unlock)
12721267 rc = cifs_unlock_range(cfile, flock, xid);
12731268