Lines Matching +full:tcon +full:- +full:channel
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/backing-dev.h>
83 current->comm, current->tgid); in cifs_posix_convert_flags()
124 struct cifs_tcon *tcon; in cifs_posix_open() local
130 return -ENOMEM; in cifs_posix_open()
138 tcon = tlink_tcon(tlink); in cifs_posix_open()
142 rc = CIFSPOSIXCreate(xid, tcon, posix_flags, mode, pnetfid, presp_data, in cifs_posix_open()
143 poplock, full_path, cifs_sb->local_nls, in cifs_posix_open()
150 if (presp_data->Type == cpu_to_le32(-1)) in cifs_posix_open()
163 rc = -ENOMEM; in cifs_posix_open()
177 struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock, in cifs_nt_open() argument
185 struct TCP_Server_Info *server = tcon->ses->server; in cifs_nt_open()
188 if (!server->ops->open) in cifs_nt_open()
189 return -ENOSYS; in cifs_nt_open()
197 * ---------- ---------------- in cifs_nt_open()
223 return -ENOMEM; in cifs_nt_open()
232 oparms.tcon = tcon; in cifs_nt_open()
241 rc = server->ops->open(xid, &oparms, oplock, buf); in cifs_nt_open()
247 if (tcon->unix_ext) in cifs_nt_open()
248 rc = cifs_get_inode_info_unix(&inode, full_path, inode->i_sb, in cifs_nt_open()
251 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, in cifs_nt_open()
255 server->ops->close(xid, tcon, fid); in cifs_nt_open()
256 if (rc == -ESTALE) in cifs_nt_open()
257 rc = -EOPENSTALE; in cifs_nt_open()
271 down_read(&cinode->lock_sem); in cifs_has_mand_locks()
272 list_for_each_entry(cur, &cinode->llist, llist) { in cifs_has_mand_locks()
273 if (!list_empty(&cur->locks)) { in cifs_has_mand_locks()
278 up_read(&cinode->lock_sem); in cifs_has_mand_locks()
300 struct cifs_tcon *tcon = tlink_tcon(tlink); in cifs_new_fileinfo() local
301 struct TCP_Server_Info *server = tcon->ses->server; in cifs_new_fileinfo()
313 INIT_LIST_HEAD(&fdlocks->locks); in cifs_new_fileinfo()
314 fdlocks->cfile = cfile; in cifs_new_fileinfo()
315 cfile->llist = fdlocks; in cifs_new_fileinfo()
317 cfile->count = 1; in cifs_new_fileinfo()
318 cfile->pid = current->tgid; in cifs_new_fileinfo()
319 cfile->uid = current_fsuid(); in cifs_new_fileinfo()
320 cfile->dentry = dget(dentry); in cifs_new_fileinfo()
321 cfile->f_flags = file->f_flags; in cifs_new_fileinfo()
322 cfile->invalidHandle = false; in cifs_new_fileinfo()
323 cfile->tlink = cifs_get_tlink(tlink); in cifs_new_fileinfo()
324 INIT_WORK(&cfile->oplock_break, cifs_oplock_break); in cifs_new_fileinfo()
325 INIT_WORK(&cfile->put, cifsFileInfo_put_work); in cifs_new_fileinfo()
326 mutex_init(&cfile->fh_mutex); in cifs_new_fileinfo()
327 spin_lock_init(&cfile->file_info_lock); in cifs_new_fileinfo()
329 cifs_sb_active(inode->i_sb); in cifs_new_fileinfo()
335 if (server->ops->is_read_op(oplock) && cifs_has_mand_locks(cinode)) { in cifs_new_fileinfo()
340 cifs_down_write(&cinode->lock_sem); in cifs_new_fileinfo()
341 list_add(&fdlocks->llist, &cinode->llist); in cifs_new_fileinfo()
342 up_write(&cinode->lock_sem); in cifs_new_fileinfo()
344 spin_lock(&tcon->open_file_lock); in cifs_new_fileinfo()
345 if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock) in cifs_new_fileinfo()
346 oplock = fid->pending_open->oplock; in cifs_new_fileinfo()
347 list_del(&fid->pending_open->olist); in cifs_new_fileinfo()
349 fid->purge_cache = false; in cifs_new_fileinfo()
350 server->ops->set_fid(cfile, fid, oplock); in cifs_new_fileinfo()
352 list_add(&cfile->tlist, &tcon->openFileList); in cifs_new_fileinfo()
353 atomic_inc(&tcon->num_local_opens); in cifs_new_fileinfo()
356 spin_lock(&cinode->open_file_lock); in cifs_new_fileinfo()
357 if (file->f_mode & FMODE_READ) in cifs_new_fileinfo()
358 list_add(&cfile->flist, &cinode->openFileList); in cifs_new_fileinfo()
360 list_add_tail(&cfile->flist, &cinode->openFileList); in cifs_new_fileinfo()
361 spin_unlock(&cinode->open_file_lock); in cifs_new_fileinfo()
362 spin_unlock(&tcon->open_file_lock); in cifs_new_fileinfo()
364 if (fid->purge_cache) in cifs_new_fileinfo()
367 file->private_data = cfile; in cifs_new_fileinfo()
374 spin_lock(&cifs_file->file_info_lock); in cifsFileInfo_get()
376 spin_unlock(&cifs_file->file_info_lock); in cifsFileInfo_get()
382 struct inode *inode = d_inode(cifs_file->dentry); in cifsFileInfo_put_final()
385 struct super_block *sb = inode->i_sb; in cifsFileInfo_put_final()
391 cifs_down_write(&cifsi->lock_sem); in cifsFileInfo_put_final()
392 list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) { in cifsFileInfo_put_final()
393 list_del(&li->llist); in cifsFileInfo_put_final()
397 list_del(&cifs_file->llist->llist); in cifsFileInfo_put_final()
398 kfree(cifs_file->llist); in cifsFileInfo_put_final()
399 up_write(&cifsi->lock_sem); in cifsFileInfo_put_final()
401 cifs_put_tlink(cifs_file->tlink); in cifsFileInfo_put_final()
402 dput(cifs_file->dentry); in cifsFileInfo_put_final()
416 * cifsFileInfo_put - release a reference of file priv data
426 * _cifsFileInfo_put - release a reference of file priv data
429 * server. Must be called without holding tcon->open_file_lock,
430 * cinode->open_file_lock and cifs_file->file_info_lock.
441 struct inode *inode = d_inode(cifs_file->dentry); in _cifsFileInfo_put()
442 struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); in _cifsFileInfo_put() local
443 struct TCP_Server_Info *server = tcon->ses->server; in _cifsFileInfo_put()
445 struct super_block *sb = inode->i_sb; in _cifsFileInfo_put()
451 spin_lock(&tcon->open_file_lock); in _cifsFileInfo_put()
452 spin_lock(&cifsi->open_file_lock); in _cifsFileInfo_put()
453 spin_lock(&cifs_file->file_info_lock); in _cifsFileInfo_put()
454 if (--cifs_file->count > 0) { in _cifsFileInfo_put()
455 spin_unlock(&cifs_file->file_info_lock); in _cifsFileInfo_put()
456 spin_unlock(&cifsi->open_file_lock); in _cifsFileInfo_put()
457 spin_unlock(&tcon->open_file_lock); in _cifsFileInfo_put()
460 spin_unlock(&cifs_file->file_info_lock); in _cifsFileInfo_put()
462 if (server->ops->get_lease_key) in _cifsFileInfo_put()
463 server->ops->get_lease_key(inode, &fid); in _cifsFileInfo_put()
466 cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open); in _cifsFileInfo_put()
469 list_del(&cifs_file->flist); in _cifsFileInfo_put()
470 list_del(&cifs_file->tlist); in _cifsFileInfo_put()
471 atomic_dec(&tcon->num_local_opens); in _cifsFileInfo_put()
473 if (list_empty(&cifsi->openFileList)) { in _cifsFileInfo_put()
475 d_inode(cifs_file->dentry)); in _cifsFileInfo_put()
481 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) in _cifsFileInfo_put()
482 set_bit(CIFS_INO_INVALID_MAPPING, &cifsi->flags); in _cifsFileInfo_put()
486 spin_unlock(&cifsi->open_file_lock); in _cifsFileInfo_put()
487 spin_unlock(&tcon->open_file_lock); in _cifsFileInfo_put()
490 cancel_work_sync(&cifs_file->oplock_break) : false; in _cifsFileInfo_put()
492 if (!tcon->need_reconnect && !cifs_file->invalidHandle) { in _cifsFileInfo_put()
493 struct TCP_Server_Info *server = tcon->ses->server; in _cifsFileInfo_put()
497 if (server->ops->close_getattr) in _cifsFileInfo_put()
498 server->ops->close_getattr(xid, tcon, cifs_file); in _cifsFileInfo_put()
499 else if (server->ops->close) in _cifsFileInfo_put()
500 server->ops->close(xid, tcon, &cifs_file->fid); in _cifsFileInfo_put()
510 queue_work(fileinfo_put_wq, &cifs_file->put); in _cifsFileInfo_put()
518 int rc = -EACCES; in cifs_open()
523 struct cifs_tcon *tcon; in cifs_open() local
533 cifs_sb = CIFS_SB(inode->i_sb); in cifs_open()
539 tcon = tlink_tcon(tlink); in cifs_open()
540 server = tcon->ses->server; in cifs_open()
544 rc = -ENOMEM; in cifs_open()
549 inode, file->f_flags, full_path); in cifs_open()
551 if (file->f_flags & O_DIRECT && in cifs_open()
552 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) { in cifs_open()
553 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) in cifs_open()
554 file->f_op = &cifs_file_direct_nobrl_ops; in cifs_open()
556 file->f_op = &cifs_file_direct_ops; in cifs_open()
559 if (server->oplocks) in cifs_open()
564 if (!tcon->broken_posix_open && tcon->unix_ext && in cifs_open()
565 cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & in cifs_open()
566 le64_to_cpu(tcon->fsUnixInfo.Capability))) { in cifs_open()
568 rc = cifs_posix_open(full_path, &inode, inode->i_sb, in cifs_open()
569 cifs_sb->mnt_file_mode /* ignored */, in cifs_open()
570 file->f_flags, &oplock, &fid.netfid, xid); in cifs_open()
574 } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { in cifs_open()
575 if (tcon->ses->serverNOS) in cifs_open()
577 tcon->ses->serverName, in cifs_open()
578 tcon->ses->serverNOS); in cifs_open()
579 tcon->broken_posix_open = true; in cifs_open()
580 } else if ((rc != -EIO) && (rc != -EREMOTE) && in cifs_open()
581 (rc != -EOPNOTSUPP)) /* path not found or net err */ in cifs_open()
589 if (server->ops->get_lease_key) in cifs_open()
590 server->ops->get_lease_key(inode, &fid); in cifs_open()
595 if (server->ops->get_lease_key) in cifs_open()
596 server->ops->get_lease_key(inode, &fid); in cifs_open()
598 rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, in cifs_open()
599 file->f_flags, &oplock, &fid, xid); in cifs_open()
608 if (server->ops->close) in cifs_open()
609 server->ops->close(xid, tcon, &fid); in cifs_open()
611 rc = -ENOMEM; in cifs_open()
617 if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { in cifs_open()
620 * problems creating new read-only files. in cifs_open()
623 .mode = inode->i_mode, in cifs_open()
631 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid, in cifs_open()
632 cfile->pid); in cifs_open()
651 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); in cifs_relock_file()
652 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_relock_file()
653 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_relock_file() local
656 down_read_nested(&cinode->lock_sem, SINGLE_DEPTH_NESTING); in cifs_relock_file()
657 if (cinode->can_cache_brlcks) { in cifs_relock_file()
658 /* can cache locks - no need to relock */ in cifs_relock_file()
659 up_read(&cinode->lock_sem); in cifs_relock_file()
663 if (cap_unix(tcon->ses) && in cifs_relock_file()
664 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && in cifs_relock_file()
665 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) in cifs_relock_file()
668 rc = tcon->ses->server->ops->push_mand_locks(cfile); in cifs_relock_file()
670 up_read(&cinode->lock_sem); in cifs_relock_file()
677 int rc = -EACCES; in cifs_reopen_file()
681 struct cifs_tcon *tcon; in cifs_reopen_file() local
692 mutex_lock(&cfile->fh_mutex); in cifs_reopen_file()
693 if (!cfile->invalidHandle) { in cifs_reopen_file()
694 mutex_unlock(&cfile->fh_mutex); in cifs_reopen_file()
700 inode = d_inode(cfile->dentry); in cifs_reopen_file()
701 cifs_sb = CIFS_SB(inode->i_sb); in cifs_reopen_file()
702 tcon = tlink_tcon(cfile->tlink); in cifs_reopen_file()
703 server = tcon->ses->server; in cifs_reopen_file()
711 full_path = build_path_from_dentry(cfile->dentry); in cifs_reopen_file()
713 rc = -ENOMEM; in cifs_reopen_file()
714 mutex_unlock(&cfile->fh_mutex); in cifs_reopen_file()
720 inode, cfile->f_flags, full_path); in cifs_reopen_file()
722 if (tcon->ses->server->oplocks) in cifs_reopen_file()
727 if (tcon->unix_ext && cap_unix(tcon->ses) && in cifs_reopen_file()
729 le64_to_cpu(tcon->fsUnixInfo.Capability))) { in cifs_reopen_file()
734 unsigned int oflags = cfile->f_flags & in cifs_reopen_file()
737 rc = cifs_posix_open(full_path, NULL, inode->i_sb, in cifs_reopen_file()
738 cifs_sb->mnt_file_mode /* ignored */, in cifs_reopen_file()
739 oflags, &oplock, &cfile->fid.netfid, xid); in cifs_reopen_file()
751 desired_access = cifs_convert_flags(cfile->f_flags); in cifs_reopen_file()
754 if (cfile->f_flags & O_SYNC) in cifs_reopen_file()
757 if (cfile->f_flags & O_DIRECT) in cifs_reopen_file()
760 if (server->ops->get_lease_key) in cifs_reopen_file()
761 server->ops->get_lease_key(inode, &cfile->fid); in cifs_reopen_file()
763 oparms.tcon = tcon; in cifs_reopen_file()
769 oparms.fid = &cfile->fid; in cifs_reopen_file()
774 * ops->open and then calling get_inode_info with returned buf since in cifs_reopen_file()
779 rc = server->ops->open(xid, &oparms, &oplock, NULL); in cifs_reopen_file()
780 if (rc == -ENOENT && oparms.reconnect == false) { in cifs_reopen_file()
781 /* durable handle timeout is expired - open the file again */ in cifs_reopen_file()
782 rc = server->ops->open(xid, &oparms, &oplock, NULL); in cifs_reopen_file()
788 mutex_unlock(&cfile->fh_mutex); in cifs_reopen_file()
795 cfile->invalidHandle = false; in cifs_reopen_file()
796 mutex_unlock(&cfile->fh_mutex); in cifs_reopen_file()
800 rc = filemap_write_and_wait(inode->i_mapping); in cifs_reopen_file()
802 mapping_set_error(inode->i_mapping, rc); in cifs_reopen_file()
804 if (tcon->posix_extensions) in cifs_reopen_file()
805 rc = smb311_posix_get_inode_info(&inode, full_path, inode->i_sb, xid); in cifs_reopen_file()
806 else if (tcon->unix_ext) in cifs_reopen_file()
808 inode->i_sb, xid); in cifs_reopen_file()
811 inode->i_sb, xid, NULL); in cifs_reopen_file()
824 if (server->ops->is_read_op(oplock) && cifs_has_mand_locks(cinode)) { in cifs_reopen_file()
829 server->ops->set_fid(cfile, &cfile->fid, oplock); in cifs_reopen_file()
841 if (file->private_data != NULL) { in cifs_close()
842 _cifsFileInfo_put(file->private_data, true, false); in cifs_close()
843 file->private_data = NULL; in cifs_close()
846 /* return code from the ->release op is always ignored */ in cifs_close()
851 cifs_reopen_persistent_handles(struct cifs_tcon *tcon) in cifs_reopen_persistent_handles() argument
858 if (!tcon->use_persistent || !tcon->need_reopen_files) in cifs_reopen_persistent_handles()
861 tcon->need_reopen_files = false; in cifs_reopen_persistent_handles()
867 spin_lock(&tcon->open_file_lock); in cifs_reopen_persistent_handles()
868 list_for_each(tmp, &tcon->openFileList) { in cifs_reopen_persistent_handles()
870 if (!open_file->invalidHandle) in cifs_reopen_persistent_handles()
873 list_add_tail(&open_file->rlist, &tmp_list); in cifs_reopen_persistent_handles()
875 spin_unlock(&tcon->open_file_lock); in cifs_reopen_persistent_handles()
880 tcon->need_reopen_files = true; in cifs_reopen_persistent_handles()
881 list_del_init(&open_file->rlist); in cifs_reopen_persistent_handles()
890 struct cifsFileInfo *cfile = file->private_data; in cifs_closedir()
891 struct cifs_tcon *tcon; in cifs_closedir() local
901 tcon = tlink_tcon(cfile->tlink); in cifs_closedir()
902 server = tcon->ses->server; in cifs_closedir()
905 spin_lock(&cfile->file_info_lock); in cifs_closedir()
906 if (server->ops->dir_needs_close(cfile)) { in cifs_closedir()
907 cfile->invalidHandle = true; in cifs_closedir()
908 spin_unlock(&cfile->file_info_lock); in cifs_closedir()
909 if (server->ops->close_dir) in cifs_closedir()
910 rc = server->ops->close_dir(xid, tcon, &cfile->fid); in cifs_closedir()
912 rc = -ENOSYS; in cifs_closedir()
917 spin_unlock(&cfile->file_info_lock); in cifs_closedir()
919 buf = cfile->srch_inf.ntwrk_buf_start; in cifs_closedir()
922 cfile->srch_inf.ntwrk_buf_start = NULL; in cifs_closedir()
923 if (cfile->srch_inf.smallBuf) in cifs_closedir()
929 cifs_put_tlink(cfile->tlink); in cifs_closedir()
930 kfree(file->private_data); in cifs_closedir()
931 file->private_data = NULL; in cifs_closedir()
944 lock->offset = offset; in cifs_lock_init()
945 lock->length = length; in cifs_lock_init()
946 lock->type = type; in cifs_lock_init()
947 lock->pid = current->tgid; in cifs_lock_init()
948 lock->flags = flags; in cifs_lock_init()
949 INIT_LIST_HEAD(&lock->blist); in cifs_lock_init()
950 init_waitqueue_head(&lock->block_q); in cifs_lock_init()
958 list_for_each_entry_safe(li, tmp, &lock->blist, blist) { in cifs_del_lock_waiters()
959 list_del_init(&li->blist); in cifs_del_lock_waiters()
960 wake_up(&li->block_q); in cifs_del_lock_waiters()
968 /* @rw_check : 0 - no op, 1 - read, 2 - write */
976 struct cifsFileInfo *cur_cfile = fdlocks->cfile; in cifs_find_fid_lock_conflict()
977 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in cifs_find_fid_lock_conflict()
979 list_for_each_entry(li, &fdlocks->locks, llist) { in cifs_find_fid_lock_conflict()
980 if (offset + length <= li->offset || in cifs_find_fid_lock_conflict()
981 offset >= li->offset + li->length) in cifs_find_fid_lock_conflict()
983 if (rw_check != CIFS_LOCK_OP && current->tgid == li->pid && in cifs_find_fid_lock_conflict()
984 server->ops->compare_fids(cfile, cur_cfile)) { in cifs_find_fid_lock_conflict()
986 if (!(li->type & server->vals->shared_lock_type) || in cifs_find_fid_lock_conflict()
990 if ((type & server->vals->shared_lock_type) && in cifs_find_fid_lock_conflict()
991 ((server->ops->compare_fids(cfile, cur_cfile) && in cifs_find_fid_lock_conflict()
992 current->tgid == li->pid) || type == li->type)) in cifs_find_fid_lock_conflict()
995 (flags & FL_OFDLCK) && (li->flags & FL_OFDLCK) && in cifs_find_fid_lock_conflict()
996 server->ops->compare_fids(cfile, cur_cfile)) in cifs_find_fid_lock_conflict()
1012 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_find_lock_conflict()
1014 list_for_each_entry(cur, &cinode->llist, llist) { in cifs_find_lock_conflict()
1038 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_lock_test()
1039 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in cifs_lock_test()
1042 down_read(&cinode->lock_sem); in cifs_lock_test()
1045 flock->fl_flags, &conf_lock, in cifs_lock_test()
1048 flock->fl_start = conf_lock->offset; in cifs_lock_test()
1049 flock->fl_end = conf_lock->offset + conf_lock->length - 1; in cifs_lock_test()
1050 flock->fl_pid = conf_lock->pid; in cifs_lock_test()
1051 if (conf_lock->type & server->vals->shared_lock_type) in cifs_lock_test()
1052 flock->fl_type = F_RDLCK; in cifs_lock_test()
1054 flock->fl_type = F_WRLCK; in cifs_lock_test()
1055 } else if (!cinode->can_cache_brlcks) in cifs_lock_test()
1058 flock->fl_type = F_UNLCK; in cifs_lock_test()
1060 up_read(&cinode->lock_sem); in cifs_lock_test()
1067 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_lock_add()
1068 cifs_down_write(&cinode->lock_sem); in cifs_lock_add()
1069 list_add_tail(&lock->llist, &cfile->llist->locks); in cifs_lock_add()
1070 up_write(&cinode->lock_sem); in cifs_lock_add()
1074 * Set the byte-range lock (mandatory style). Returns:
1077 * 3) -EACCES, if there is a lock that prevents us and wait is false.
1084 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_lock_add_if()
1090 cifs_down_write(&cinode->lock_sem); in cifs_lock_add_if()
1092 exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, in cifs_lock_add_if()
1093 lock->type, lock->flags, &conf_lock, in cifs_lock_add_if()
1095 if (!exist && cinode->can_cache_brlcks) { in cifs_lock_add_if()
1096 list_add_tail(&lock->llist, &cfile->llist->locks); in cifs_lock_add_if()
1097 up_write(&cinode->lock_sem); in cifs_lock_add_if()
1104 rc = -EACCES; in cifs_lock_add_if()
1106 list_add_tail(&lock->blist, &conf_lock->blist); in cifs_lock_add_if()
1107 up_write(&cinode->lock_sem); in cifs_lock_add_if()
1108 rc = wait_event_interruptible(lock->block_q, in cifs_lock_add_if()
1109 (lock->blist.prev == &lock->blist) && in cifs_lock_add_if()
1110 (lock->blist.next == &lock->blist)); in cifs_lock_add_if()
1113 cifs_down_write(&cinode->lock_sem); in cifs_lock_add_if()
1114 list_del_init(&lock->blist); in cifs_lock_add_if()
1117 up_write(&cinode->lock_sem); in cifs_lock_add_if()
1133 unsigned char saved_type = flock->fl_type; in cifs_posix_lock_test()
1135 if ((flock->fl_flags & FL_POSIX) == 0) in cifs_posix_lock_test()
1138 down_read(&cinode->lock_sem); in cifs_posix_lock_test()
1141 if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { in cifs_posix_lock_test()
1142 flock->fl_type = saved_type; in cifs_posix_lock_test()
1146 up_read(&cinode->lock_sem); in cifs_posix_lock_test()
1151 * Set the byte-range lock (posix style). Returns:
1163 if ((flock->fl_flags & FL_POSIX) == 0) in cifs_posix_lock_set()
1166 cifs_down_write(&cinode->lock_sem); in cifs_posix_lock_set()
1167 if (!cinode->can_cache_brlcks) { in cifs_posix_lock_set()
1168 up_write(&cinode->lock_sem); in cifs_posix_lock_set()
1173 up_write(&cinode->lock_sem); in cifs_posix_lock_set()
1183 struct cifs_tcon *tcon; in cifs_push_mandatory_locks() local
1193 tcon = tlink_tcon(cfile->tlink); in cifs_push_mandatory_locks()
1196 * Accessing maxBuf is racy with cifs_reconnect - need to store value in cifs_push_mandatory_locks()
1199 max_buf = tcon->ses->server->maxBuf; in cifs_push_mandatory_locks()
1202 return -EINVAL; in cifs_push_mandatory_locks()
1207 max_buf = min_t(unsigned int, max_buf - sizeof(struct smb_hdr), in cifs_push_mandatory_locks()
1209 max_num = (max_buf - sizeof(struct smb_hdr)) / in cifs_push_mandatory_locks()
1214 return -ENOMEM; in cifs_push_mandatory_locks()
1220 list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { in cifs_push_mandatory_locks()
1221 if (li->type != types[i]) in cifs_push_mandatory_locks()
1223 cur->Pid = cpu_to_le16(li->pid); in cifs_push_mandatory_locks()
1224 cur->LengthLow = cpu_to_le32((u32)li->length); in cifs_push_mandatory_locks()
1225 cur->LengthHigh = cpu_to_le32((u32)(li->length>>32)); in cifs_push_mandatory_locks()
1226 cur->OffsetLow = cpu_to_le32((u32)li->offset); in cifs_push_mandatory_locks()
1227 cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); in cifs_push_mandatory_locks()
1229 stored_rc = cifs_lockv(xid, tcon, in cifs_push_mandatory_locks()
1230 cfile->fid.netfid, in cifs_push_mandatory_locks()
1231 (__u8)li->type, 0, num, in cifs_push_mandatory_locks()
1242 stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, in cifs_push_mandatory_locks()
1272 struct inode *inode = d_inode(cfile->dentry); in cifs_push_posix_locks()
1273 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_push_posix_locks() local
1275 struct file_lock_context *flctx = inode->i_flctx; in cifs_push_posix_locks()
1287 spin_lock(&flctx->flc_lock); in cifs_push_posix_locks()
1288 list_for_each(el, &flctx->flc_posix) { in cifs_push_posix_locks()
1291 spin_unlock(&flctx->flc_lock); in cifs_push_posix_locks()
1297 * added to the list while we are holding cinode->lock_sem that in cifs_push_posix_locks()
1303 rc = -ENOMEM; in cifs_push_posix_locks()
1306 list_add_tail(&lck->llist, &locks_to_send); in cifs_push_posix_locks()
1310 spin_lock(&flctx->flc_lock); in cifs_push_posix_locks()
1311 list_for_each_entry(flock, &flctx->flc_posix, fl_list) { in cifs_push_posix_locks()
1315 * structures - something is really wrong. in cifs_push_posix_locks()
1320 length = 1 + flock->fl_end - flock->fl_start; in cifs_push_posix_locks()
1321 if (flock->fl_type == F_RDLCK || flock->fl_type == F_SHLCK) in cifs_push_posix_locks()
1326 lck->pid = hash_lockowner(flock->fl_owner); in cifs_push_posix_locks()
1327 lck->netfid = cfile->fid.netfid; in cifs_push_posix_locks()
1328 lck->length = length; in cifs_push_posix_locks()
1329 lck->type = type; in cifs_push_posix_locks()
1330 lck->offset = flock->fl_start; in cifs_push_posix_locks()
1332 spin_unlock(&flctx->flc_lock); in cifs_push_posix_locks()
1337 stored_rc = CIFSSMBPosixLock(xid, tcon, lck->netfid, lck->pid, in cifs_push_posix_locks()
1338 lck->offset, lck->length, NULL, in cifs_push_posix_locks()
1339 lck->type, 0); in cifs_push_posix_locks()
1342 list_del(&lck->llist); in cifs_push_posix_locks()
1351 list_del(&lck->llist); in cifs_push_posix_locks()
1360 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); in cifs_push_locks()
1361 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_push_locks()
1362 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_push_locks() local
1365 /* we are going to update can_cache_brlcks here - need a write access */ in cifs_push_locks()
1366 cifs_down_write(&cinode->lock_sem); in cifs_push_locks()
1367 if (!cinode->can_cache_brlcks) { in cifs_push_locks()
1368 up_write(&cinode->lock_sem); in cifs_push_locks()
1372 if (cap_unix(tcon->ses) && in cifs_push_locks()
1373 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && in cifs_push_locks()
1374 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) in cifs_push_locks()
1377 rc = tcon->ses->server->ops->push_mand_locks(cfile); in cifs_push_locks()
1379 cinode->can_cache_brlcks = false; in cifs_push_locks()
1380 up_write(&cinode->lock_sem); in cifs_push_locks()
1388 if (flock->fl_flags & FL_POSIX) in cifs_read_flock()
1390 if (flock->fl_flags & FL_FLOCK) in cifs_read_flock()
1392 if (flock->fl_flags & FL_SLEEP) { in cifs_read_flock()
1396 if (flock->fl_flags & FL_ACCESS) in cifs_read_flock()
1397 cifs_dbg(FYI, "Process suspended by mandatory locking - not implemented yet\n"); in cifs_read_flock()
1398 if (flock->fl_flags & FL_LEASE) in cifs_read_flock()
1399 cifs_dbg(FYI, "Lease on file - not implemented yet\n"); in cifs_read_flock()
1400 if (flock->fl_flags & in cifs_read_flock()
1403 cifs_dbg(FYI, "Unknown lock flags 0x%x\n", flock->fl_flags); in cifs_read_flock()
1405 *type = server->vals->large_lock_type; in cifs_read_flock()
1406 if (flock->fl_type == F_WRLCK) { in cifs_read_flock()
1408 *type |= server->vals->exclusive_lock_type; in cifs_read_flock()
1410 } else if (flock->fl_type == F_UNLCK) { in cifs_read_flock()
1412 *type |= server->vals->unlock_lock_type; in cifs_read_flock()
1415 } else if (flock->fl_type == F_RDLCK) { in cifs_read_flock()
1417 *type |= server->vals->shared_lock_type; in cifs_read_flock()
1419 } else if (flock->fl_type == F_EXLCK) { in cifs_read_flock()
1421 *type |= server->vals->exclusive_lock_type; in cifs_read_flock()
1423 } else if (flock->fl_type == F_SHLCK) { in cifs_read_flock()
1425 *type |= server->vals->shared_lock_type; in cifs_read_flock()
1436 __u64 length = 1 + flock->fl_end - flock->fl_start; in cifs_getlk()
1437 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; in cifs_getlk()
1438 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_getlk() local
1439 struct TCP_Server_Info *server = tcon->ses->server; in cifs_getlk()
1440 __u16 netfid = cfile->fid.netfid; in cifs_getlk()
1449 if (type & server->vals->shared_lock_type) in cifs_getlk()
1453 rc = CIFSSMBPosixLock(xid, tcon, netfid, in cifs_getlk()
1454 hash_lockowner(flock->fl_owner), in cifs_getlk()
1455 flock->fl_start, length, flock, in cifs_getlk()
1460 rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock); in cifs_getlk()
1465 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type, in cifs_getlk()
1468 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, in cifs_getlk()
1470 flock->fl_type = F_UNLCK; in cifs_getlk()
1477 if (type & server->vals->shared_lock_type) { in cifs_getlk()
1478 flock->fl_type = F_WRLCK; in cifs_getlk()
1482 type &= ~server->vals->exclusive_lock_type; in cifs_getlk()
1484 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, in cifs_getlk()
1485 type | server->vals->shared_lock_type, in cifs_getlk()
1488 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, in cifs_getlk()
1489 type | server->vals->shared_lock_type, 0, 1, false); in cifs_getlk()
1490 flock->fl_type = F_RDLCK; in cifs_getlk()
1495 flock->fl_type = F_WRLCK; in cifs_getlk()
1514 list_del(&li->llist); in cifs_free_llist()
1531 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_unlock_range() local
1532 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_unlock_range()
1534 __u64 length = 1 + flock->fl_end - flock->fl_start; in cifs_unlock_range()
1540 * Accessing maxBuf is racy with cifs_reconnect - need to store value in cifs_unlock_range()
1543 max_buf = tcon->ses->server->maxBuf; in cifs_unlock_range()
1545 return -EINVAL; in cifs_unlock_range()
1549 max_buf = min_t(unsigned int, max_buf - sizeof(struct smb_hdr), in cifs_unlock_range()
1551 max_num = (max_buf - sizeof(struct smb_hdr)) / in cifs_unlock_range()
1555 return -ENOMEM; in cifs_unlock_range()
1557 cifs_down_write(&cinode->lock_sem); in cifs_unlock_range()
1561 list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { in cifs_unlock_range()
1562 if (flock->fl_start > li->offset || in cifs_unlock_range()
1563 (flock->fl_start + length) < in cifs_unlock_range()
1564 (li->offset + li->length)) in cifs_unlock_range()
1566 if (current->tgid != li->pid) in cifs_unlock_range()
1568 if (types[i] != li->type) in cifs_unlock_range()
1570 if (cinode->can_cache_brlcks) { in cifs_unlock_range()
1572 * We can cache brlock requests - simply remove in cifs_unlock_range()
1575 list_del(&li->llist); in cifs_unlock_range()
1580 cur->Pid = cpu_to_le16(li->pid); in cifs_unlock_range()
1581 cur->LengthLow = cpu_to_le32((u32)li->length); in cifs_unlock_range()
1582 cur->LengthHigh = cpu_to_le32((u32)(li->length>>32)); in cifs_unlock_range()
1583 cur->OffsetLow = cpu_to_le32((u32)li->offset); in cifs_unlock_range()
1584 cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); in cifs_unlock_range()
1590 list_move(&li->llist, &tmp_llist); in cifs_unlock_range()
1592 stored_rc = cifs_lockv(xid, tcon, in cifs_unlock_range()
1593 cfile->fid.netfid, in cifs_unlock_range()
1594 li->type, num, 0, buf); in cifs_unlock_range()
1598 * request - add all locks from the tmp in cifs_unlock_range()
1602 &cfile->llist->locks); in cifs_unlock_range()
1606 * The unlock range request succeed - in cifs_unlock_range()
1616 stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, in cifs_unlock_range()
1620 &cfile->llist->locks); in cifs_unlock_range()
1627 up_write(&cinode->lock_sem); in cifs_unlock_range()
1638 __u64 length = 1 + flock->fl_end - flock->fl_start; in cifs_setlk()
1639 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; in cifs_setlk()
1640 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_setlk() local
1641 struct TCP_Server_Info *server = tcon->ses->server; in cifs_setlk()
1642 struct inode *inode = d_inode(cfile->dentry); in cifs_setlk()
1651 if (type & server->vals->shared_lock_type) in cifs_setlk()
1659 rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, in cifs_setlk()
1660 hash_lockowner(flock->fl_owner), in cifs_setlk()
1661 flock->fl_start, length, in cifs_setlk()
1669 lock = cifs_lock_init(flock->fl_start, length, type, in cifs_setlk()
1670 flock->fl_flags); in cifs_setlk()
1672 return -ENOMEM; in cifs_setlk()
1684 * if we set a byte-range lock on a file - break it explicitly in cifs_setlk()
1686 * read won't conflict with non-overlapted locks due to in cifs_setlk()
1694 CIFS_I(inode)->oplock = 0; in cifs_setlk()
1697 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, in cifs_setlk()
1706 rc = server->ops->mand_unlock_range(cfile, flock, xid); in cifs_setlk()
1709 if ((flock->fl_flags & FL_POSIX) || (flock->fl_flags & FL_FLOCK)) { in cifs_setlk()
1718 if (!(flock->fl_flags & FL_CLOSE)) in cifs_setlk()
1733 struct cifs_tcon *tcon; in cifs_flock() local
1737 rc = -EACCES; in cifs_flock()
1740 if (!(fl->fl_flags & FL_FLOCK)) in cifs_flock()
1741 return -ENOLCK; in cifs_flock()
1743 cfile = (struct cifsFileInfo *)file->private_data; in cifs_flock()
1744 tcon = tlink_tcon(cfile->tlink); in cifs_flock()
1747 tcon->ses->server); in cifs_flock()
1750 if (cap_unix(tcon->ses) && in cifs_flock()
1751 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && in cifs_flock()
1752 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) in cifs_flock()
1761 return -EOPNOTSUPP; in cifs_flock()
1779 struct cifs_tcon *tcon; in cifs_lock() local
1783 rc = -EACCES; in cifs_lock()
1787 cmd, flock->fl_flags, flock->fl_type, in cifs_lock()
1788 flock->fl_start, flock->fl_end); in cifs_lock()
1790 cfile = (struct cifsFileInfo *)file->private_data; in cifs_lock()
1791 tcon = tlink_tcon(cfile->tlink); in cifs_lock()
1794 tcon->ses->server); in cifs_lock()
1797 if (cap_unix(tcon->ses) && in cifs_lock()
1798 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && in cifs_lock()
1799 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) in cifs_lock()
1817 return -EOPNOTSUPP; in cifs_lock()
1828 * the inode->i_lock held
1836 if (end_of_write > cifsi->server_eof) in cifs_update_eof()
1837 cifsi->server_eof = end_of_write; in cifs_update_eof()
1847 struct cifs_tcon *tcon; in cifs_write() local
1850 struct dentry *dentry = open_file->dentry; in cifs_write()
1857 tcon = tlink_tcon(open_file->tlink); in cifs_write()
1858 server = tcon->ses->server; in cifs_write()
1860 if (!server->ops->sync_write) in cifs_write()
1861 return -ENOSYS; in cifs_write()
1867 rc = -EAGAIN; in cifs_write()
1868 while (rc == -EAGAIN) { in cifs_write()
1872 if (open_file->invalidHandle) { in cifs_write()
1882 len = min(server->ops->wp_retry_size(d_inode(dentry)), in cifs_write()
1883 (unsigned int)write_size - total_written); in cifs_write()
1888 io_parms.tcon = tcon; in cifs_write()
1891 rc = server->ops->sync_write(xid, &open_file->fid, in cifs_write()
1902 spin_lock(&d_inode(dentry)->i_lock); in cifs_write()
1904 spin_unlock(&d_inode(dentry)->i_lock); in cifs_write()
1909 cifs_stats_bytes_written(tcon, total_written); in cifs_write()
1912 spin_lock(&d_inode(dentry)->i_lock); in cifs_write()
1913 if (*offset > d_inode(dentry)->i_size) in cifs_write()
1915 spin_unlock(&d_inode(dentry)->i_lock); in cifs_write()
1926 struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); in find_readable_file()
1929 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) in find_readable_file()
1932 spin_lock(&cifs_inode->open_file_lock); in find_readable_file()
1933 /* we could simply get the first_list_entry since write-only entries in find_readable_file()
1936 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { in find_readable_file()
1937 if (fsuid_only && !uid_eq(open_file->uid, current_fsuid())) in find_readable_file()
1939 if (OPEN_FMODE(open_file->f_flags) & FMODE_READ) { in find_readable_file()
1940 if (!open_file->invalidHandle) { in find_readable_file()
1944 spin_unlock(&cifs_inode->open_file_lock); in find_readable_file()
1952 spin_unlock(&cifs_inode->open_file_lock); in find_readable_file()
1956 /* Return -EBADF if no handle is found and general rc otherwise */
1964 int rc = -EBADF; in cifs_get_writable_file()
1971 * Having a null inode here (because mapping->host was set to zero by in cifs_get_writable_file()
1982 cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); in cifs_get_writable_file()
1985 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) in cifs_get_writable_file()
1988 spin_lock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
1991 spin_unlock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
1994 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { in cifs_get_writable_file()
1995 if (!any_available && open_file->pid != current->tgid) in cifs_get_writable_file()
1997 if (fsuid_only && !uid_eq(open_file->uid, current_fsuid())) in cifs_get_writable_file()
1999 if (with_delete && !(open_file->fid.access & DELETE)) in cifs_get_writable_file()
2001 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { in cifs_get_writable_file()
2002 if (!open_file->invalidHandle) { in cifs_get_writable_file()
2005 spin_unlock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
2025 spin_unlock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
2034 spin_lock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
2035 list_move_tail(&inv_file->flist, &cifs_inode->openFileList); in cifs_get_writable_file()
2036 spin_unlock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
2040 spin_lock(&cifs_inode->open_file_lock); in cifs_get_writable_file()
2061 cifs_get_writable_path(struct cifs_tcon *tcon, const char *name, in cifs_get_writable_path() argument
2072 spin_lock(&tcon->open_file_lock); in cifs_get_writable_path()
2073 list_for_each(tmp, &tcon->openFileList) { in cifs_get_writable_path()
2076 full_path = build_path_from_dentry(cfile->dentry); in cifs_get_writable_path()
2078 spin_unlock(&tcon->open_file_lock); in cifs_get_writable_path()
2079 return -ENOMEM; in cifs_get_writable_path()
2087 cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_get_writable_path()
2088 spin_unlock(&tcon->open_file_lock); in cifs_get_writable_path()
2092 spin_unlock(&tcon->open_file_lock); in cifs_get_writable_path()
2093 return -ENOENT; in cifs_get_writable_path()
2097 cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, in cifs_get_readable_path() argument
2107 spin_lock(&tcon->open_file_lock); in cifs_get_readable_path()
2108 list_for_each(tmp, &tcon->openFileList) { in cifs_get_readable_path()
2111 full_path = build_path_from_dentry(cfile->dentry); in cifs_get_readable_path()
2113 spin_unlock(&tcon->open_file_lock); in cifs_get_readable_path()
2114 return -ENOMEM; in cifs_get_readable_path()
2122 cinode = CIFS_I(d_inode(cfile->dentry)); in cifs_get_readable_path()
2123 spin_unlock(&tcon->open_file_lock); in cifs_get_readable_path()
2125 return *ret_file ? 0 : -ENOENT; in cifs_get_readable_path()
2128 spin_unlock(&tcon->open_file_lock); in cifs_get_readable_path()
2129 return -ENOENT; in cifs_get_readable_path()
2134 struct address_space *mapping = page->mapping; in cifs_partialpagewrite()
2135 loff_t offset = (loff_t)page->index << PAGE_SHIFT; in cifs_partialpagewrite()
2137 int rc = -EFAULT; in cifs_partialpagewrite()
2142 if (!mapping || !mapping->host) in cifs_partialpagewrite()
2143 return -EFAULT; in cifs_partialpagewrite()
2145 inode = page->mapping->host; in cifs_partialpagewrite()
2153 return -EIO; in cifs_partialpagewrite()
2157 if (offset > mapping->host->i_size) { in cifs_partialpagewrite()
2163 if (mapping->host->i_size - offset < (loff_t)to) in cifs_partialpagewrite()
2164 to = (unsigned)(mapping->host->i_size - offset); in cifs_partialpagewrite()
2166 rc = cifs_get_writable_file(CIFS_I(mapping->host), FIND_WR_ANY, in cifs_partialpagewrite()
2169 bytes_written = cifs_write(open_file, open_file->pid, in cifs_partialpagewrite()
2170 write_data, to - from, &offset); in cifs_partialpagewrite()
2173 inode->i_atime = inode->i_mtime = current_time(inode); in cifs_partialpagewrite()
2179 rc = -EFAULT; in cifs_partialpagewrite()
2183 rc = -EIO; in cifs_partialpagewrite()
2203 PAGECACHE_TAG_DIRTY, tofind, wdata->pages); in wdata_alloc_and_fillpages()
2217 page = wdata->pages[i]; in wdata_prepare_pages()
2221 * (changing page->mapping to NULL), or even swizzled in wdata_prepare_pages()
2230 if (unlikely(page->mapping != mapping)) { in wdata_prepare_pages()
2235 if (!wbc->range_cyclic && page->index > end) { in wdata_prepare_pages()
2241 if (*next && (page->index != *next)) { in wdata_prepare_pages()
2247 if (wbc->sync_mode != WB_SYNC_NONE) in wdata_prepare_pages()
2261 if (page_offset(page) >= i_size_read(mapping->host)) { in wdata_prepare_pages()
2268 wdata->pages[i] = page; in wdata_prepare_pages()
2269 *next = page->index + 1; in wdata_prepare_pages()
2275 *index = wdata->pages[0]->index + 1; in wdata_prepare_pages()
2279 put_page(wdata->pages[i]); in wdata_prepare_pages()
2280 wdata->pages[i] = NULL; in wdata_prepare_pages()
2292 wdata->sync_mode = wbc->sync_mode; in wdata_send_pages()
2293 wdata->nr_pages = nr_pages; in wdata_send_pages()
2294 wdata->offset = page_offset(wdata->pages[0]); in wdata_send_pages()
2295 wdata->pagesz = PAGE_SIZE; in wdata_send_pages()
2296 wdata->tailsz = min(i_size_read(mapping->host) - in wdata_send_pages()
2297 page_offset(wdata->pages[nr_pages - 1]), in wdata_send_pages()
2299 wdata->bytes = ((nr_pages - 1) * PAGE_SIZE) + wdata->tailsz; in wdata_send_pages()
2300 wdata->pid = wdata->cfile->pid; in wdata_send_pages()
2302 rc = adjust_credits(wdata->server, &wdata->credits, wdata->bytes); in wdata_send_pages()
2306 if (wdata->cfile->invalidHandle) in wdata_send_pages()
2307 rc = -EAGAIN; in wdata_send_pages()
2309 rc = wdata->server->ops->async_writev(wdata, in wdata_send_pages()
2318 struct inode *inode = mapping->host; in cifs_writepages()
2319 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in cifs_writepages()
2333 if (cifs_sb->wsize < PAGE_SIZE) in cifs_writepages()
2337 if (wbc->range_cyclic) { in cifs_writepages()
2338 index = mapping->writeback_index; /* Start from prev offset */ in cifs_writepages()
2339 end = -1; in cifs_writepages()
2341 index = wbc->range_start >> PAGE_SHIFT; in cifs_writepages()
2342 end = wbc->range_end >> PAGE_SHIFT; in cifs_writepages()
2343 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) in cifs_writepages()
2347 server = cifs_pick_channel(cifs_sb_master_tcon(cifs_sb)->ses); in cifs_writepages()
2366 rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, in cifs_writepages()
2373 tofind = min((wsize / PAGE_SIZE) - 1, end - index) + 1; in cifs_writepages()
2378 rc = -ENOMEM; in cifs_writepages()
2385 kref_put(&wdata->refcount, cifs_writedata_release); in cifs_writepages()
2395 kref_put(&wdata->refcount, cifs_writedata_release); in cifs_writepages()
2400 wdata->credits = credits_on_stack; in cifs_writepages()
2401 wdata->cfile = cfile; in cifs_writepages()
2402 wdata->server = server; in cifs_writepages()
2405 if (!wdata->cfile) { in cifs_writepages()
2411 rc = -EBADF; in cifs_writepages()
2416 unlock_page(wdata->pages[i]); in cifs_writepages()
2418 /* send failure -- clean up the mess */ in cifs_writepages()
2420 add_credits_and_wake_if(server, &wdata->credits, 0); in cifs_writepages()
2424 wdata->pages[i]); in cifs_writepages()
2426 SetPageError(wdata->pages[i]); in cifs_writepages()
2427 end_page_writeback(wdata->pages[i]); in cifs_writepages()
2428 put_page(wdata->pages[i]); in cifs_writepages()
2433 kref_put(&wdata->refcount, cifs_writedata_release); in cifs_writepages()
2435 if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN) { in cifs_writepages()
2449 wbc->nr_to_write -= nr_pages; in cifs_writepages()
2450 if (wbc->nr_to_write <= 0) in cifs_writepages()
2469 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) in cifs_writepages()
2470 mapping->writeback_index = index; in cifs_writepages()
2488 cifs_dbg(FYI, "ppw - page not up to date\n"); in cifs_writepage_locked()
2494 * or re-dirty the page with "redirty_page_for_writepage()" in in cifs_writepage_locked()
2497 * Just unlocking the page will cause the radix tree tag-bits in cifs_writepage_locked()
2504 if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN) in cifs_writepage_locked()
2509 mapping_set_error(page->mapping, rc); in cifs_writepage_locked()
2531 struct inode *inode = mapping->host; in cifs_write_end()
2532 struct cifsFileInfo *cfile = file->private_data; in cifs_write_end()
2533 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); in cifs_write_end()
2536 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) in cifs_write_end()
2537 pid = cfile->pid; in cifs_write_end()
2539 pid = current->tgid; in cifs_write_end()
2553 unsigned offset = pos & (PAGE_SIZE - 1); in cifs_write_end()
2575 spin_lock(&inode->i_lock); in cifs_write_end()
2576 if (pos > inode->i_size) in cifs_write_end()
2578 spin_unlock(&inode->i_lock); in cifs_write_end()
2592 struct cifs_tcon *tcon; in cifs_strict_fsync() local
2594 struct cifsFileInfo *smbfile = file->private_data; in cifs_strict_fsync()
2596 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in cifs_strict_fsync()
2600 trace_cifs_fsync_err(inode->i_ino, rc); in cifs_strict_fsync()
2606 cifs_dbg(FYI, "Sync file - name: %pD datasync: 0x%x\n", in cifs_strict_fsync()
2617 tcon = tlink_tcon(smbfile->tlink); in cifs_strict_fsync()
2618 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { in cifs_strict_fsync()
2619 server = tcon->ses->server; in cifs_strict_fsync()
2620 if (server->ops->flush) in cifs_strict_fsync()
2621 rc = server->ops->flush(xid, tcon, &smbfile->fid); in cifs_strict_fsync()
2623 rc = -ENOSYS; in cifs_strict_fsync()
2634 struct cifs_tcon *tcon; in cifs_fsync() local
2636 struct cifsFileInfo *smbfile = file->private_data; in cifs_fsync()
2641 trace_cifs_fsync_err(file_inode(file)->i_ino, rc); in cifs_fsync()
2647 cifs_dbg(FYI, "Sync file - name: %pD datasync: 0x%x\n", in cifs_fsync()
2650 tcon = tlink_tcon(smbfile->tlink); in cifs_fsync()
2651 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { in cifs_fsync()
2652 server = tcon->ses->server; in cifs_fsync()
2653 if (server->ops->flush) in cifs_fsync()
2654 rc = server->ops->flush(xid, tcon, &smbfile->fid); in cifs_fsync()
2656 rc = -ENOSYS; in cifs_fsync()
2672 if (file->f_mode & FMODE_WRITE) in cifs_flush()
2673 rc = filemap_write_and_wait(inode->i_mapping); in cifs_flush()
2677 trace_cifs_flush_err(inode->i_ino, rc); in cifs_flush()
2695 rc = -ENOMEM; in cifs_write_allocate_pages()
2729 kref_put(&wdata->ctx->refcount, cifs_aio_ctx_release); in cifs_uncached_writedata_release()
2730 for (i = 0; i < wdata->nr_pages; i++) in cifs_uncached_writedata_release()
2731 put_page(wdata->pages[i]); in cifs_uncached_writedata_release()
2742 struct inode *inode = d_inode(wdata->cfile->dentry); in cifs_uncached_writev_complete()
2745 spin_lock(&inode->i_lock); in cifs_uncached_writev_complete()
2746 cifs_update_eof(cifsi, wdata->offset, wdata->bytes); in cifs_uncached_writev_complete()
2747 if (cifsi->server_eof > inode->i_size) in cifs_uncached_writev_complete()
2748 i_size_write(inode, cifsi->server_eof); in cifs_uncached_writev_complete()
2749 spin_unlock(&inode->i_lock); in cifs_uncached_writev_complete()
2751 complete(&wdata->done); in cifs_uncached_writev_complete()
2752 collect_uncached_write_data(wdata->ctx); in cifs_uncached_writev_complete()
2754 kref_put(&wdata->refcount, cifs_uncached_writedata_release); in cifs_uncached_writev_complete()
2767 copied = copy_page_from_iter(wdata->pages[i], 0, bytes, from); in wdata_fill_from_iovec()
2768 cur_len -= copied; in wdata_fill_from_iovec()
2773 * loop, we'll likely end up getting a zero-length in wdata_fill_from_iovec()
2779 cur_len = save_len - cur_len; in wdata_fill_from_iovec()
2785 * the address in the iovec was bogus. Return -EFAULT and let in wdata_fill_from_iovec()
2789 return -EFAULT; in wdata_fill_from_iovec()
2806 struct TCP_Server_Info *server = wdata->server; in cifs_resend_wdata()
2809 if (wdata->cfile->invalidHandle) { in cifs_resend_wdata()
2810 rc = cifs_reopen_file(wdata->cfile, false); in cifs_resend_wdata()
2811 if (rc == -EAGAIN) in cifs_resend_wdata()
2824 rc = server->ops->wait_mtu_credits(server, wdata->bytes, in cifs_resend_wdata()
2829 if (wsize < wdata->bytes) { in cifs_resend_wdata()
2833 } while (wsize < wdata->bytes); in cifs_resend_wdata()
2834 wdata->credits = credits; in cifs_resend_wdata()
2836 rc = adjust_credits(server, &wdata->credits, wdata->bytes); in cifs_resend_wdata()
2839 if (wdata->cfile->invalidHandle) in cifs_resend_wdata()
2840 rc = -EAGAIN; in cifs_resend_wdata()
2843 if (wdata->mr) { in cifs_resend_wdata()
2844 wdata->mr->need_invalidate = true; in cifs_resend_wdata()
2845 smbd_deregister_mr(wdata->mr); in cifs_resend_wdata()
2846 wdata->mr = NULL; in cifs_resend_wdata()
2849 rc = server->ops->async_writev(wdata, in cifs_resend_wdata()
2856 list_add_tail(&wdata->list, wdata_list); in cifs_resend_wdata()
2861 add_credits_and_wake_if(server, &wdata->credits, 0); in cifs_resend_wdata()
2862 } while (rc == -EAGAIN); in cifs_resend_wdata()
2865 kref_put(&wdata->refcount, cifs_uncached_writedata_release); in cifs_resend_wdata()
2887 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) in cifs_write_from_iter()
2888 pid = open_file->pid; in cifs_write_from_iter()
2890 pid = current->tgid; in cifs_write_from_iter()
2892 server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses); in cifs_write_from_iter()
2900 if (open_file->invalidHandle) { in cifs_write_from_iter()
2902 if (rc == -EAGAIN) in cifs_write_from_iter()
2908 rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, in cifs_write_from_iter()
2915 if (ctx->direct_io) { in cifs_write_from_iter()
2924 from->iov_offset, from->count); in cifs_write_from_iter()
2935 (cur_len + start + PAGE_SIZE - 1) / PAGE_SIZE; in cifs_write_from_iter()
2940 rc = -ENOMEM; in cifs_write_from_iter()
2946 wdata->page_offset = start; in cifs_write_from_iter()
2947 wdata->tailsz = in cifs_write_from_iter()
2949 cur_len - (PAGE_SIZE - start) - in cifs_write_from_iter()
2950 (nr_pages - 2) * PAGE_SIZE : in cifs_write_from_iter()
2957 rc = -ENOMEM; in cifs_write_from_iter()
2962 rc = cifs_write_allocate_pages(wdata->pages, nr_pages); in cifs_write_from_iter()
2964 kvfree(wdata->pages); in cifs_write_from_iter()
2975 put_page(wdata->pages[i]); in cifs_write_from_iter()
2976 kvfree(wdata->pages); in cifs_write_from_iter()
2986 for ( ; nr_pages > num_pages; nr_pages--) in cifs_write_from_iter()
2987 put_page(wdata->pages[nr_pages - 1]); in cifs_write_from_iter()
2989 wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); in cifs_write_from_iter()
2992 wdata->sync_mode = WB_SYNC_ALL; in cifs_write_from_iter()
2993 wdata->nr_pages = nr_pages; in cifs_write_from_iter()
2994 wdata->offset = (__u64)offset; in cifs_write_from_iter()
2995 wdata->cfile = cifsFileInfo_get(open_file); in cifs_write_from_iter()
2996 wdata->server = server; in cifs_write_from_iter()
2997 wdata->pid = pid; in cifs_write_from_iter()
2998 wdata->bytes = cur_len; in cifs_write_from_iter()
2999 wdata->pagesz = PAGE_SIZE; in cifs_write_from_iter()
3000 wdata->credits = credits_on_stack; in cifs_write_from_iter()
3001 wdata->ctx = ctx; in cifs_write_from_iter()
3002 kref_get(&ctx->refcount); in cifs_write_from_iter()
3004 rc = adjust_credits(server, &wdata->credits, wdata->bytes); in cifs_write_from_iter()
3007 if (wdata->cfile->invalidHandle) in cifs_write_from_iter()
3008 rc = -EAGAIN; in cifs_write_from_iter()
3010 rc = server->ops->async_writev(wdata, in cifs_write_from_iter()
3015 add_credits_and_wake_if(server, &wdata->credits, 0); in cifs_write_from_iter()
3016 kref_put(&wdata->refcount, in cifs_write_from_iter()
3018 if (rc == -EAGAIN) { in cifs_write_from_iter()
3020 iov_iter_advance(from, offset - saved_offset); in cifs_write_from_iter()
3026 list_add_tail(&wdata->list, wdata_list); in cifs_write_from_iter()
3028 len -= cur_len; in cifs_write_from_iter()
3038 struct cifs_tcon *tcon; in collect_uncached_write_data() local
3040 struct dentry *dentry = ctx->cfile->dentry; in collect_uncached_write_data()
3043 tcon = tlink_tcon(ctx->cfile->tlink); in collect_uncached_write_data()
3044 cifs_sb = CIFS_SB(dentry->d_sb); in collect_uncached_write_data()
3046 mutex_lock(&ctx->aio_mutex); in collect_uncached_write_data()
3048 if (list_empty(&ctx->list)) { in collect_uncached_write_data()
3049 mutex_unlock(&ctx->aio_mutex); in collect_uncached_write_data()
3053 rc = ctx->rc; in collect_uncached_write_data()
3060 list_for_each_entry_safe(wdata, tmp, &ctx->list, list) { in collect_uncached_write_data()
3062 if (!try_wait_for_completion(&wdata->done)) { in collect_uncached_write_data()
3063 mutex_unlock(&ctx->aio_mutex); in collect_uncached_write_data()
3067 if (wdata->result) in collect_uncached_write_data()
3068 rc = wdata->result; in collect_uncached_write_data()
3070 ctx->total_len += wdata->bytes; in collect_uncached_write_data()
3073 if (rc == -EAGAIN) { in collect_uncached_write_data()
3075 struct iov_iter tmp_from = ctx->iter; in collect_uncached_write_data()
3078 list_del_init(&wdata->list); in collect_uncached_write_data()
3080 if (ctx->direct_io) in collect_uncached_write_data()
3085 wdata->offset - ctx->pos); in collect_uncached_write_data()
3087 rc = cifs_write_from_iter(wdata->offset, in collect_uncached_write_data()
3088 wdata->bytes, &tmp_from, in collect_uncached_write_data()
3089 ctx->cfile, cifs_sb, &tmp_list, in collect_uncached_write_data()
3092 kref_put(&wdata->refcount, in collect_uncached_write_data()
3096 list_splice(&tmp_list, &ctx->list); in collect_uncached_write_data()
3100 list_del_init(&wdata->list); in collect_uncached_write_data()
3101 kref_put(&wdata->refcount, cifs_uncached_writedata_release); in collect_uncached_write_data()
3104 cifs_stats_bytes_written(tcon, ctx->total_len); in collect_uncached_write_data()
3105 set_bit(CIFS_INO_INVALID_MAPPING, &CIFS_I(dentry->d_inode)->flags); in collect_uncached_write_data()
3107 ctx->rc = (rc == 0) ? ctx->total_len : rc; in collect_uncached_write_data()
3109 mutex_unlock(&ctx->aio_mutex); in collect_uncached_write_data()
3111 if (ctx->iocb && ctx->iocb->ki_complete) in collect_uncached_write_data()
3112 ctx->iocb->ki_complete(ctx->iocb, ctx->rc, 0); in collect_uncached_write_data()
3114 complete(&ctx->done); in collect_uncached_write_data()
3120 struct file *file = iocb->ki_filp; in __cifs_writev()
3123 struct cifs_tcon *tcon; in __cifs_writev() local
3132 * In this case, fall back to non-direct write function. in __cifs_writev()
3136 cifs_dbg(FYI, "use non-direct cifs_writev for kvec I/O\n"); in __cifs_writev()
3145 cfile = file->private_data; in __cifs_writev()
3146 tcon = tlink_tcon(cfile->tlink); in __cifs_writev()
3148 if (!tcon->ses->server->ops->async_writev) in __cifs_writev()
3149 return -ENOSYS; in __cifs_writev()
3153 return -ENOMEM; in __cifs_writev()
3155 ctx->cfile = cifsFileInfo_get(cfile); in __cifs_writev()
3158 ctx->iocb = iocb; in __cifs_writev()
3160 ctx->pos = iocb->ki_pos; in __cifs_writev()
3163 ctx->direct_io = true; in __cifs_writev()
3164 ctx->iter = *from; in __cifs_writev()
3165 ctx->len = len; in __cifs_writev()
3169 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_writev()
3175 mutex_lock(&ctx->aio_mutex); in __cifs_writev()
3177 rc = cifs_write_from_iter(iocb->ki_pos, ctx->len, &saved_from, in __cifs_writev()
3178 cfile, cifs_sb, &ctx->list, ctx); in __cifs_writev()
3186 if (!list_empty(&ctx->list)) in __cifs_writev()
3189 mutex_unlock(&ctx->aio_mutex); in __cifs_writev()
3192 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_writev()
3197 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_writev()
3198 return -EIOCBQUEUED; in __cifs_writev()
3201 rc = wait_for_completion_killable(&ctx->done); in __cifs_writev()
3203 mutex_lock(&ctx->aio_mutex); in __cifs_writev()
3204 ctx->rc = rc = -EINTR; in __cifs_writev()
3205 total_written = ctx->total_len; in __cifs_writev()
3206 mutex_unlock(&ctx->aio_mutex); in __cifs_writev()
3208 rc = ctx->rc; in __cifs_writev()
3209 total_written = ctx->total_len; in __cifs_writev()
3212 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_writev()
3217 iocb->ki_pos += total_written; in __cifs_writev()
3234 struct file *file = iocb->ki_filp; in cifs_writev()
3235 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; in cifs_writev()
3236 struct inode *inode = file->f_mapping->host; in cifs_writev()
3238 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in cifs_writev()
3246 down_read(&cinode->lock_sem); in cifs_writev()
3252 if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from), in cifs_writev()
3253 server->vals->exclusive_lock_type, 0, in cifs_writev()
3257 rc = -EACCES; in cifs_writev()
3259 up_read(&cinode->lock_sem); in cifs_writev()
3270 struct inode *inode = file_inode(iocb->ki_filp); in cifs_strict_writev()
3272 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in cifs_strict_writev()
3274 iocb->ki_filp->private_data; in cifs_strict_writev()
3275 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_strict_writev() local
3283 if (cap_unix(tcon->ses) && in cifs_strict_writev()
3284 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) in cifs_strict_writev()
3285 && ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) { in cifs_strict_writev()
3293 * For non-oplocked files in strict cache mode we need to write the data in cifs_strict_writev()
3294 * to the server exactly from the pos to pos+len-1 rather than flush all in cifs_strict_writev()
3296 * these pages but not on the region from pos to ppos+len-1. in cifs_strict_writev()
3310 cinode->oplock = 0; in cifs_strict_writev()
3324 rdata->pages = pages; in cifs_readdata_direct_alloc()
3325 kref_init(&rdata->refcount); in cifs_readdata_direct_alloc()
3326 INIT_LIST_HEAD(&rdata->list); in cifs_readdata_direct_alloc()
3327 init_completion(&rdata->done); in cifs_readdata_direct_alloc()
3328 INIT_WORK(&rdata->work, complete); in cifs_readdata_direct_alloc()
3356 if (rdata->mr) { in cifs_readdata_release()
3357 smbd_deregister_mr(rdata->mr); in cifs_readdata_release()
3358 rdata->mr = NULL; in cifs_readdata_release()
3361 if (rdata->cfile) in cifs_readdata_release()
3362 cifsFileInfo_put(rdata->cfile); in cifs_readdata_release()
3364 kvfree(rdata->pages); in cifs_readdata_release()
3378 rc = -ENOMEM; in cifs_read_allocate_pages()
3381 rdata->pages[i] = page; in cifs_read_allocate_pages()
3388 put_page(rdata->pages[i]); in cifs_read_allocate_pages()
3389 rdata->pages[i] = NULL; in cifs_read_allocate_pages()
3402 kref_put(&rdata->ctx->refcount, cifs_aio_ctx_release); in cifs_uncached_readdata_release()
3403 for (i = 0; i < rdata->nr_pages; i++) { in cifs_uncached_readdata_release()
3404 put_page(rdata->pages[i]); in cifs_uncached_readdata_release()
3410 * cifs_readdata_to_iov - copy data from pages in response to an iovec
3421 size_t remaining = rdata->got_bytes; in cifs_readdata_to_iov()
3424 for (i = 0; i < rdata->nr_pages; i++) { in cifs_readdata_to_iov()
3425 struct page *page = rdata->pages[i]; in cifs_readdata_to_iov()
3436 remaining -= written; in cifs_readdata_to_iov()
3440 return remaining ? -EFAULT : 0; in cifs_readdata_to_iov()
3451 complete(&rdata->done); in cifs_uncached_readv_complete()
3452 collect_uncached_read_data(rdata->ctx); in cifs_uncached_readv_complete()
3454 kref_put(&rdata->refcount, cifs_uncached_readdata_release); in cifs_uncached_readv_complete()
3464 unsigned int nr_pages = rdata->nr_pages; in uncached_fill_pages()
3465 unsigned int page_offset = rdata->page_offset; in uncached_fill_pages()
3467 rdata->got_bytes = 0; in uncached_fill_pages()
3468 rdata->tailsz = PAGE_SIZE; in uncached_fill_pages()
3470 struct page *page = rdata->pages[i]; in uncached_fill_pages()
3472 unsigned int segment_size = rdata->pagesz; in uncached_fill_pages()
3475 segment_size -= page_offset; in uncached_fill_pages()
3482 rdata->pages[i] = NULL; in uncached_fill_pages()
3483 rdata->nr_pages--; in uncached_fill_pages()
3493 rdata->tailsz = len; in uncached_fill_pages()
3494 len -= n; in uncached_fill_pages()
3500 else if (rdata->mr) in uncached_fill_pages()
3509 rdata->got_bytes += result; in uncached_fill_pages()
3512 return rdata->got_bytes > 0 && result != -ECONNABORTED ? in uncached_fill_pages()
3513 rdata->got_bytes : result; in uncached_fill_pages()
3528 return uncached_fill_pages(server, rdata, iter, iter->count); in cifs_uncached_copy_into_pages()
3540 /* XXX: should we pick a new channel here? */ in cifs_resend_rdata()
3541 server = rdata->server; in cifs_resend_rdata()
3544 if (rdata->cfile->invalidHandle) { in cifs_resend_rdata()
3545 rc = cifs_reopen_file(rdata->cfile, true); in cifs_resend_rdata()
3546 if (rc == -EAGAIN) in cifs_resend_rdata()
3558 rc = server->ops->wait_mtu_credits(server, rdata->bytes, in cifs_resend_rdata()
3564 if (rsize < rdata->bytes) { in cifs_resend_rdata()
3568 } while (rsize < rdata->bytes); in cifs_resend_rdata()
3569 rdata->credits = credits; in cifs_resend_rdata()
3571 rc = adjust_credits(server, &rdata->credits, rdata->bytes); in cifs_resend_rdata()
3573 if (rdata->cfile->invalidHandle) in cifs_resend_rdata()
3574 rc = -EAGAIN; in cifs_resend_rdata()
3577 if (rdata->mr) { in cifs_resend_rdata()
3578 rdata->mr->need_invalidate = true; in cifs_resend_rdata()
3579 smbd_deregister_mr(rdata->mr); in cifs_resend_rdata()
3580 rdata->mr = NULL; in cifs_resend_rdata()
3583 rc = server->ops->async_readv(rdata); in cifs_resend_rdata()
3590 list_add_tail(&rdata->list, rdata_list); in cifs_resend_rdata()
3595 add_credits_and_wake_if(server, &rdata->credits, 0); in cifs_resend_rdata()
3596 } while (rc == -EAGAIN); in cifs_resend_rdata()
3599 kref_put(&rdata->refcount, cifs_uncached_readdata_release); in cifs_resend_rdata()
3618 struct iov_iter direct_iov = ctx->iter; in cifs_send_async_read()
3620 server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses); in cifs_send_async_read()
3622 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) in cifs_send_async_read()
3623 pid = open_file->pid; in cifs_send_async_read()
3625 pid = current->tgid; in cifs_send_async_read()
3627 if (ctx->direct_io) in cifs_send_async_read()
3628 iov_iter_advance(&direct_iov, offset - ctx->pos); in cifs_send_async_read()
3631 if (open_file->invalidHandle) { in cifs_send_async_read()
3633 if (rc == -EAGAIN) in cifs_send_async_read()
3639 rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, in cifs_send_async_read()
3646 if (ctx->direct_io) { in cifs_send_async_read()
3671 rc = -ENOMEM; in cifs_send_async_read()
3675 npages = (cur_len + start + PAGE_SIZE-1) / PAGE_SIZE; in cifs_send_async_read()
3676 rdata->page_offset = start; in cifs_send_async_read()
3677 rdata->tailsz = npages > 1 ? in cifs_send_async_read()
3678 cur_len-(PAGE_SIZE-start)-(npages-2)*PAGE_SIZE : in cifs_send_async_read()
3689 rc = -ENOMEM; in cifs_send_async_read()
3695 kvfree(rdata->pages); in cifs_send_async_read()
3701 rdata->tailsz = PAGE_SIZE; in cifs_send_async_read()
3704 rdata->server = server; in cifs_send_async_read()
3705 rdata->cfile = cifsFileInfo_get(open_file); in cifs_send_async_read()
3706 rdata->nr_pages = npages; in cifs_send_async_read()
3707 rdata->offset = offset; in cifs_send_async_read()
3708 rdata->bytes = cur_len; in cifs_send_async_read()
3709 rdata->pid = pid; in cifs_send_async_read()
3710 rdata->pagesz = PAGE_SIZE; in cifs_send_async_read()
3711 rdata->read_into_pages = cifs_uncached_read_into_pages; in cifs_send_async_read()
3712 rdata->copy_into_pages = cifs_uncached_copy_into_pages; in cifs_send_async_read()
3713 rdata->credits = credits_on_stack; in cifs_send_async_read()
3714 rdata->ctx = ctx; in cifs_send_async_read()
3715 kref_get(&ctx->refcount); in cifs_send_async_read()
3717 rc = adjust_credits(server, &rdata->credits, rdata->bytes); in cifs_send_async_read()
3720 if (rdata->cfile->invalidHandle) in cifs_send_async_read()
3721 rc = -EAGAIN; in cifs_send_async_read()
3723 rc = server->ops->async_readv(rdata); in cifs_send_async_read()
3727 add_credits_and_wake_if(server, &rdata->credits, 0); in cifs_send_async_read()
3728 kref_put(&rdata->refcount, in cifs_send_async_read()
3730 if (rc == -EAGAIN) { in cifs_send_async_read()
3737 list_add_tail(&rdata->list, rdata_list); in cifs_send_async_read()
3739 len -= cur_len; in cifs_send_async_read()
3749 struct iov_iter *to = &ctx->iter; in collect_uncached_read_data()
3753 cifs_sb = CIFS_SB(ctx->cfile->dentry->d_sb); in collect_uncached_read_data()
3755 mutex_lock(&ctx->aio_mutex); in collect_uncached_read_data()
3757 if (list_empty(&ctx->list)) { in collect_uncached_read_data()
3758 mutex_unlock(&ctx->aio_mutex); in collect_uncached_read_data()
3762 rc = ctx->rc; in collect_uncached_read_data()
3765 list_for_each_entry_safe(rdata, tmp, &ctx->list, list) { in collect_uncached_read_data()
3767 if (!try_wait_for_completion(&rdata->done)) { in collect_uncached_read_data()
3768 mutex_unlock(&ctx->aio_mutex); in collect_uncached_read_data()
3772 if (rdata->result == -EAGAIN) { in collect_uncached_read_data()
3775 unsigned int got_bytes = rdata->got_bytes; in collect_uncached_read_data()
3777 list_del_init(&rdata->list); in collect_uncached_read_data()
3782 * happened -- fill the buffer and continue in collect_uncached_read_data()
3785 if (got_bytes && got_bytes < rdata->bytes) { in collect_uncached_read_data()
3787 if (!ctx->direct_io) in collect_uncached_read_data()
3790 kref_put(&rdata->refcount, in collect_uncached_read_data()
3796 if (ctx->direct_io) { in collect_uncached_read_data()
3798 * Re-use rdata as this is a in collect_uncached_read_data()
3806 rdata->offset + got_bytes, in collect_uncached_read_data()
3807 rdata->bytes - got_bytes, in collect_uncached_read_data()
3808 rdata->cfile, cifs_sb, in collect_uncached_read_data()
3811 kref_put(&rdata->refcount, in collect_uncached_read_data()
3815 list_splice(&tmp_list, &ctx->list); in collect_uncached_read_data()
3818 } else if (rdata->result) in collect_uncached_read_data()
3819 rc = rdata->result; in collect_uncached_read_data()
3820 else if (!ctx->direct_io) in collect_uncached_read_data()
3823 /* if there was a short read -- discard anything left */ in collect_uncached_read_data()
3824 if (rdata->got_bytes && rdata->got_bytes < rdata->bytes) in collect_uncached_read_data()
3825 rc = -ENODATA; in collect_uncached_read_data()
3827 ctx->total_len += rdata->got_bytes; in collect_uncached_read_data()
3829 list_del_init(&rdata->list); in collect_uncached_read_data()
3830 kref_put(&rdata->refcount, cifs_uncached_readdata_release); in collect_uncached_read_data()
3833 if (!ctx->direct_io) in collect_uncached_read_data()
3834 ctx->total_len = ctx->len - iov_iter_count(to); in collect_uncached_read_data()
3837 if (rc == -ENODATA) in collect_uncached_read_data()
3840 ctx->rc = (rc == 0) ? (ssize_t)ctx->total_len : rc; in collect_uncached_read_data()
3842 mutex_unlock(&ctx->aio_mutex); in collect_uncached_read_data()
3844 if (ctx->iocb && ctx->iocb->ki_complete) in collect_uncached_read_data()
3845 ctx->iocb->ki_complete(ctx->iocb, ctx->rc, 0); in collect_uncached_read_data()
3847 complete(&ctx->done); in collect_uncached_read_data()
3854 struct file *file = iocb->ki_filp; in __cifs_readv()
3857 struct cifs_tcon *tcon; in __cifs_readv() local
3859 loff_t offset = iocb->ki_pos; in __cifs_readv()
3868 cifs_dbg(FYI, "use non-direct cifs_user_readv for kvec I/O\n"); in __cifs_readv()
3877 cfile = file->private_data; in __cifs_readv()
3878 tcon = tlink_tcon(cfile->tlink); in __cifs_readv()
3880 if (!tcon->ses->server->ops->async_readv) in __cifs_readv()
3881 return -ENOSYS; in __cifs_readv()
3883 if ((file->f_flags & O_ACCMODE) == O_WRONLY) in __cifs_readv()
3888 return -ENOMEM; in __cifs_readv()
3890 ctx->cfile = cifsFileInfo_get(cfile); in __cifs_readv()
3893 ctx->iocb = iocb; in __cifs_readv()
3896 ctx->should_dirty = true; in __cifs_readv()
3899 ctx->pos = offset; in __cifs_readv()
3900 ctx->direct_io = true; in __cifs_readv()
3901 ctx->iter = *to; in __cifs_readv()
3902 ctx->len = len; in __cifs_readv()
3906 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_readv()
3909 len = ctx->len; in __cifs_readv()
3913 mutex_lock(&ctx->aio_mutex); in __cifs_readv()
3915 rc = cifs_send_async_read(offset, len, cfile, cifs_sb, &ctx->list, ctx); in __cifs_readv()
3918 if (!list_empty(&ctx->list)) in __cifs_readv()
3921 mutex_unlock(&ctx->aio_mutex); in __cifs_readv()
3924 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_readv()
3929 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_readv()
3930 return -EIOCBQUEUED; in __cifs_readv()
3933 rc = wait_for_completion_killable(&ctx->done); in __cifs_readv()
3935 mutex_lock(&ctx->aio_mutex); in __cifs_readv()
3936 ctx->rc = rc = -EINTR; in __cifs_readv()
3937 total_read = ctx->total_len; in __cifs_readv()
3938 mutex_unlock(&ctx->aio_mutex); in __cifs_readv()
3940 rc = ctx->rc; in __cifs_readv()
3941 total_read = ctx->total_len; in __cifs_readv()
3944 kref_put(&ctx->refcount, cifs_aio_ctx_release); in __cifs_readv()
3947 iocb->ki_pos += total_read; in __cifs_readv()
3966 struct inode *inode = file_inode(iocb->ki_filp); in cifs_strict_readv()
3968 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in cifs_strict_readv()
3970 iocb->ki_filp->private_data; in cifs_strict_readv()
3971 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_strict_readv() local
3972 int rc = -EACCES; in cifs_strict_readv()
3977 * change - so we can't make a decision about inode invalidating. in cifs_strict_readv()
3980 * pos+len-1. in cifs_strict_readv()
3985 if (cap_unix(tcon->ses) && in cifs_strict_readv()
3986 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && in cifs_strict_readv()
3987 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) in cifs_strict_readv()
3994 down_read(&cinode->lock_sem); in cifs_strict_readv()
3995 if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(to), in cifs_strict_readv()
3996 tcon->ses->server->vals->shared_lock_type, in cifs_strict_readv()
3999 up_read(&cinode->lock_sem); in cifs_strict_readv()
4006 int rc = -EACCES; in cifs_read()
4012 struct cifs_tcon *tcon; in cifs_read() local
4025 rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize); in cifs_read()
4027 if (file->private_data == NULL) { in cifs_read()
4028 rc = -EBADF; in cifs_read()
4032 open_file = file->private_data; in cifs_read()
4033 tcon = tlink_tcon(open_file->tlink); in cifs_read()
4034 server = cifs_pick_channel(tcon->ses); in cifs_read()
4036 if (!server->ops->sync_read) { in cifs_read()
4038 return -ENOSYS; in cifs_read()
4041 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) in cifs_read()
4042 pid = open_file->pid; in cifs_read()
4044 pid = current->tgid; in cifs_read()
4046 if ((file->f_flags & O_ACCMODE) == O_WRONLY) in cifs_read()
4052 current_read_size = min_t(uint, read_size - total_read, in cifs_read()
4059 if (!(tcon->ses->capabilities & in cifs_read()
4060 tcon->ses->server->vals->cap_large_files)) { in cifs_read()
4064 if (open_file->invalidHandle) { in cifs_read()
4070 io_parms.tcon = tcon; in cifs_read()
4074 rc = server->ops->sync_read(xid, &open_file->fid, &io_parms, in cifs_read()
4077 } while (rc == -EAGAIN); in cifs_read()
4087 cifs_stats_bytes_read(tcon, total_read); in cifs_read()
4102 struct page *page = vmf->page; in cifs_page_mkwrite()
4126 vma->vm_ops = &cifs_file_vm_ops; in cifs_file_strict_mmap()
4145 vma->vm_ops = &cifs_file_vm_ops; in cifs_file_mmap()
4158 got_bytes = rdata->got_bytes; in cifs_readv_complete()
4159 for (i = 0; i < rdata->nr_pages; i++) { in cifs_readv_complete()
4160 struct page *page = rdata->pages[i]; in cifs_readv_complete()
4164 if (rdata->result == 0 || in cifs_readv_complete()
4165 (rdata->result == -EAGAIN && got_bytes)) { in cifs_readv_complete()
4172 if (rdata->result == 0 || in cifs_readv_complete()
4173 (rdata->result == -EAGAIN && got_bytes)) in cifs_readv_complete()
4174 cifs_readpage_to_fscache(rdata->mapping->host, page); in cifs_readv_complete()
4176 got_bytes -= min_t(unsigned int, PAGE_SIZE, got_bytes); in cifs_readv_complete()
4179 rdata->pages[i] = NULL; in cifs_readv_complete()
4181 kref_put(&rdata->refcount, cifs_readdata_release); in cifs_readv_complete()
4193 unsigned int nr_pages = rdata->nr_pages; in readpages_fill_pages()
4194 unsigned int page_offset = rdata->page_offset; in readpages_fill_pages()
4197 eof = CIFS_I(rdata->mapping->host)->server_eof; in readpages_fill_pages()
4198 eof_index = eof ? (eof - 1) >> PAGE_SHIFT : 0; in readpages_fill_pages()
4201 rdata->got_bytes = 0; in readpages_fill_pages()
4202 rdata->tailsz = PAGE_SIZE; in readpages_fill_pages()
4204 struct page *page = rdata->pages[i]; in readpages_fill_pages()
4205 unsigned int to_read = rdata->pagesz; in readpages_fill_pages()
4209 to_read -= page_offset; in readpages_fill_pages()
4216 len -= to_read; in readpages_fill_pages()
4219 zero_user(page, len + page_offset, to_read - len); in readpages_fill_pages()
4220 n = rdata->tailsz = len; in readpages_fill_pages()
4222 } else if (page->index > eof_index) { in readpages_fill_pages()
4237 rdata->pages[i] = NULL; in readpages_fill_pages()
4238 rdata->nr_pages--; in readpages_fill_pages()
4245 rdata->pages[i] = NULL; in readpages_fill_pages()
4246 rdata->nr_pages--; in readpages_fill_pages()
4254 else if (rdata->mr) in readpages_fill_pages()
4263 rdata->got_bytes += result; in readpages_fill_pages()
4266 return rdata->got_bytes > 0 && result != -ECONNABORTED ? in readpages_fill_pages()
4267 rdata->got_bytes : result; in readpages_fill_pages()
4282 return readpages_fill_pages(server, rdata, iter, iter->count); in cifs_readpages_copy_into_pages()
4306 page->index, gfp); in readpages_get_pages()
4315 *offset = (loff_t)page->index << PAGE_SHIFT; in readpages_get_pages()
4318 list_move_tail(&page->lru, tmplist); in readpages_get_pages()
4321 expected_index = page->index + 1; in readpages_get_pages()
4324 if (page->index != expected_index) in readpages_get_pages()
4332 rc = add_to_page_cache_locked(page, mapping, page->index, gfp); in readpages_get_pages()
4337 list_move_tail(&page->lru, tmplist); in readpages_get_pages()
4351 struct cifsFileInfo *open_file = file->private_data; in cifs_readpages()
4359 * Reads as many pages as possible from fscache. Returns -ENOBUFS in cifs_readpages()
4365 rc = cifs_readpages_from_fscache(mapping->host, mapping, page_list, in cifs_readpages()
4372 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) in cifs_readpages()
4373 pid = open_file->pid; in cifs_readpages()
4375 pid = current->tgid; in cifs_readpages()
4378 server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses); in cifs_readpages()
4392 * the rdata->pages, then we want them in increasing order. in cifs_readpages()
4402 if (open_file->invalidHandle) { in cifs_readpages()
4404 if (rc == -EAGAIN) in cifs_readpages()
4410 rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, in cifs_readpages()
4439 list_del(&page->lru); in cifs_readpages()
4444 rc = -ENOMEM; in cifs_readpages()
4449 rdata->cfile = cifsFileInfo_get(open_file); in cifs_readpages()
4450 rdata->server = server; in cifs_readpages()
4451 rdata->mapping = mapping; in cifs_readpages()
4452 rdata->offset = offset; in cifs_readpages()
4453 rdata->bytes = bytes; in cifs_readpages()
4454 rdata->pid = pid; in cifs_readpages()
4455 rdata->pagesz = PAGE_SIZE; in cifs_readpages()
4456 rdata->tailsz = PAGE_SIZE; in cifs_readpages()
4457 rdata->read_into_pages = cifs_readpages_read_into_pages; in cifs_readpages()
4458 rdata->copy_into_pages = cifs_readpages_copy_into_pages; in cifs_readpages()
4459 rdata->credits = credits_on_stack; in cifs_readpages()
4462 list_del(&page->lru); in cifs_readpages()
4463 rdata->pages[rdata->nr_pages++] = page; in cifs_readpages()
4466 rc = adjust_credits(server, &rdata->credits, rdata->bytes); in cifs_readpages()
4469 if (rdata->cfile->invalidHandle) in cifs_readpages()
4470 rc = -EAGAIN; in cifs_readpages()
4472 rc = server->ops->async_readv(rdata); in cifs_readpages()
4476 add_credits_and_wake_if(server, &rdata->credits, 0); in cifs_readpages()
4477 for (i = 0; i < rdata->nr_pages; i++) { in cifs_readpages()
4478 page = rdata->pages[i]; in cifs_readpages()
4484 kref_put(&rdata->refcount, cifs_readdata_release); in cifs_readpages()
4488 kref_put(&rdata->refcount, cifs_readdata_release); in cifs_readpages()
4495 cifs_fscache_readpages_cancel(mapping->host, page_list); in cifs_readpages()
4525 file_inode(file)->i_atime = current_time(file_inode(file)); in cifs_readpage_worker()
4526 if (timespec64_compare(&(file_inode(file)->i_atime), &(file_inode(file)->i_mtime))) in cifs_readpage_worker()
4527 file_inode(file)->i_atime = file_inode(file)->i_mtime; in cifs_readpage_worker()
4529 file_inode(file)->i_atime = current_time(file_inode(file)); in cifs_readpage_worker()
4532 memset(read_data + rc, 0, PAGE_SIZE - rc); in cifs_readpage_worker()
4552 loff_t offset = (loff_t)page->index << PAGE_SHIFT; in cifs_readpage()
4553 int rc = -EACCES; in cifs_readpage()
4558 if (file->private_data == NULL) { in cifs_readpage()
4559 rc = -EBADF; in cifs_readpage()
4577 spin_lock(&cifs_inode->open_file_lock); in is_inode_writable()
4578 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { in is_inode_writable()
4579 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { in is_inode_writable()
4580 spin_unlock(&cifs_inode->open_file_lock); in is_inode_writable()
4584 spin_unlock(&cifs_inode->open_file_lock); in is_inode_writable()
4589 open for write - to avoid races with writepage extending
4590 the file - in the future we could consider allowing
4603 cifs_sb = CIFS_SB(cifsInode->vfs_inode.i_sb); in is_size_safe_to_change()
4604 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) { in is_size_safe_to_change()
4610 if (i_size_read(&cifsInode->vfs_inode) < end_of_file) in is_size_safe_to_change()
4624 loff_t offset = pos & (PAGE_SIZE - 1); in cifs_write_begin()
4635 rc = -ENOMEM; in cifs_write_begin()
4656 if (CIFS_CACHE_READ(CIFS_I(mapping->host))) { in cifs_write_begin()
4657 i_size = i_size_read(mapping->host); in cifs_write_begin()
4674 if ((file->f_flags & O_ACCMODE) != O_WRONLY && !oncethru) { in cifs_write_begin()
4685 /* we could try using another file handle if there is one - in cifs_write_begin()
4706 struct cifsInodeInfo *cifsi = CIFS_I(page->mapping->host); in cifs_invalidate_page()
4709 cifs_fscache_invalidate_page(page, &cifsi->vfs_inode); in cifs_invalidate_page()
4716 loff_t range_end = range_start + (loff_t)(PAGE_SIZE - 1); in cifs_launder_page()
4729 cifs_fscache_invalidate_page(page, page->mapping->host); in cifs_launder_page()
4737 struct inode *inode = d_inode(cfile->dentry); in cifs_oplock_break()
4739 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); in cifs_oplock_break() local
4740 struct TCP_Server_Info *server = tcon->ses->server; in cifs_oplock_break()
4744 wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS, in cifs_oplock_break()
4747 server->ops->downgrade_oplock(server, cinode, cfile->oplock_level, in cifs_oplock_break()
4748 cfile->oplock_epoch, &purge_cache); in cifs_oplock_break()
4754 cinode->oplock = 0; in cifs_oplock_break()
4757 if (inode && S_ISREG(inode->i_mode)) { in cifs_oplock_break()
4762 rc = filemap_fdatawrite(inode->i_mapping); in cifs_oplock_break()
4764 rc = filemap_fdatawait(inode->i_mapping); in cifs_oplock_break()
4765 mapping_set_error(inode->i_mapping, rc); in cifs_oplock_break()
4784 if (!cfile->oplock_break_cancelled) { in cifs_oplock_break()
4785 rc = tcon->ses->server->ops->oplock_response(tcon, &cfile->fid, in cifs_oplock_break()
4797 * In the non-cached mode (mount with cache=none), we shunt off direct read and write requests
4809 return -EINVAL; in cifs_direct_io()
4815 struct cifsFileInfo *cfile = swap_file->private_data; in cifs_swap_activate()
4816 struct inode *inode = swap_file->f_mapping->host; in cifs_swap_activate()
4822 spin_lock(&inode->i_lock); in cifs_swap_activate()
4823 blocks = inode->i_blocks; in cifs_swap_activate()
4824 isize = inode->i_size; in cifs_swap_activate()
4825 spin_unlock(&inode->i_lock); in cifs_swap_activate()
4828 return -EINVAL; in cifs_swap_activate()
4830 *span = sis->pages; in cifs_swap_activate()
4843 cfile->swapfile = true; in cifs_swap_activate()
4855 struct cifsFileInfo *cfile = file->private_data; in cifs_swap_deactivate()
4862 cfile->swapfile = false; in cifs_swap_deactivate()