Merge tag 'cifs-fixes-7.4-rc3' of https://git.manguebit.org/linux

Pull smb client fixes from Paulo Alcantara:

  - Fix silent data loss in writeback

    Since the move to netfslib a transient failure (a reconnect, a lost
    handle, an interrupted wait, -ENOMEM, or a task killed while close()
    flushes its dirty pages) ended writeback with the folios clean and
    no error, dropping the write.

    Retry it instead, bounded by the hard and retrans mount options, and
    have umount -f abort the retries and the reconnect and credit waits
    so the unmount's own sync can't hang

  - Prefer a non-O_DIRECT handle for writeback, as Windows rejects
    unaligned I/O on O_DIRECT handles and silently dropped about 1% of
    the writes in generic/051

  - netfs: keep the prepare_read() and prepare_write() errno across a
    reissue, and don't hang a read whose retry is abandoned (the
    writeback fixes depend on these)

  - Fix an out-of-bounds write when compounding an encrypted SMB2_IOCTL
    with a large input, which an unprivileged user can trigger with a
    long symlink target

  - Fix an out-of-bounds read parsing a DFS target referral, and a
    double conversion of the DFS path in setup_dfs_ref()

  - Validate security descriptor headers before allocating the query
    result, and compare owner and group SIDs by their encoded lengths

  - Hold a server reference while queueing reconnect work so the server
    can't be freed under the worker

  - Hold the inode across cifs_oplock_break() so dropping the handle
    reference can't free it before the break is acknowledged

  - Flush an inode's deferred handles before opening another of its hard
    links, so the open doesn't reuse the lease key under a mismatched
    name and get rejected with STATUS_INVALID_PARAMETER

  - Skip a NULL channel in __cifs_put_smb_ses()

  - Bound the invalid NTLMSSP signature diagnostic

* tag 'cifs-fixes-7.4-rc3' of https://git.manguebit.org/linux: (29 commits)
  smb: client: flush deferred handles of other names before a hard link open
  smb: client: hold the inode across cifs_oplock_break()
  smb: client: stop reconnecting and replaying during a forced unmount
  smb: client: fail writeback sends and reopens fast when the server is gone
  smb: client: don't replay handle reopens inside SMB2_open()
  smb: client: let umount -f stop waiting for reconnects on hard mounts
  smb: client: retry writeback after losing the connection, share or handle
  smb: client: retry writes that couldn't be issued due to a reconnect
  smb: client: don't block dying tasks waiting for writeback on fsync
  smb: client: retry writeback on interrupts and allocation failures
  smb: client: don't fail writeback preparation if the task is dying
  smb: client: issue writes from a worker if the task is dying
  smb: client: don't block dying tasks waiting for writeback on close
  smb: client: don't spend read retries on reads cut short by a reconnect
  smb: client: don't retry failed writes forever regardless of mount options
  smb: client: don't give up writeback on the first replayable error
  smb: client: let umount -f abort retried reads and writes
  netfs: don't hang a read whose retry is abandoned
  netfs: keep the prepare_read errno when abandoning read retries
  netfs: preserve prepare_write errno on reissue
  ...
This commit is contained in:
Linus Torvalds
2026-11-13 09:56:22 -08:00
19 changed files with 1157 additions and 206 deletions
+13 -4
View File
@@ -28,6 +28,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
struct netfs_io_subrequest *subreq;
struct netfs_io_stream *stream = &rreq->io_streams[0];
struct list_head *next;
int ret;
_enter("R=%x", rreq->debug_id);
@@ -140,8 +141,11 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
/* Renegotiate max_len (rsize) */
stream->sreq_max_len = subreq->len;
if (rreq->netfs_ops->prepare_read &&
rreq->netfs_ops->prepare_read(subreq) < 0) {
ret = 0;
if (rreq->netfs_ops->prepare_read)
ret = rreq->netfs_ops->prepare_read(subreq);
if (ret < 0) {
subreq->error = ret;
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
goto abandon;
@@ -221,7 +225,9 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
netfs_stat(&netfs_n_rh_download);
if (rreq->netfs_ops->prepare_read(subreq) < 0) {
ret = rreq->netfs_ops->prepare_read(subreq);
if (ret < 0) {
subreq->error = ret;
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
goto abandon;
@@ -257,10 +263,13 @@ abandon:
if (!test_bit(NETFS_SREQ_FAILED, &subreq->flags) &&
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
continue;
subreq->error = -ENOMEM;
if (!subreq->error ||
!test_bit(NETFS_SREQ_FAILED, &subreq->flags))
subreq->error = -ENOMEM;
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
}
netfs_wake_collector(rreq);
}
/*
+3 -1
View File
@@ -268,7 +268,9 @@ void netfs_reissue_write(struct netfs_io_stream *stream,
iov_iter_truncate(&subreq->io_iter, size);
subreq->retry_count++;
subreq->error = 0;
/* Keep prepare_write() errno; do_issue_write() terminates FAILED. */
if (!test_bit(NETFS_SREQ_FAILED, &subreq->flags))
subreq->error = 0;
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);
netfs_stat(&netfs_n_wh_retry_write_subreq);
+2
View File
@@ -57,6 +57,7 @@ struct cifs_sb_info {
atomic_t active;
atomic_t mnt_cifs_flags;
atomic_t outstanding_rreq; /* nr of rreqs not yet fully deinitialized */
atomic_t umount_aborts; /* nr of umount -f attempts */
struct delayed_work prune_tlinks;
struct rcu_head rcu;
@@ -68,6 +69,7 @@ struct cifs_sb_info {
* (cifs_autodisable_serverino) in order to match new mounts.
*/
bool mnt_cifs_serverino_autodisabled;
bool exiting; /* umount -f committed: stop retries */
/*
* Available once the mount has completed.
*/
+4 -1
View File
@@ -1134,7 +1134,10 @@ static void populate_new_aces(char *nacl_base,
* updated in the inode.
*/
if (!memcmp(pownersid, pgrpsid, sizeof(struct smb_sid))) {
if (pownersid->num_subauth == pgrpsid->num_subauth &&
!memcmp(pownersid, pgrpsid,
CIFS_SID_BASE_SIZE +
pownersid->num_subauth * sizeof(__le32))) {
/*
* Case when owner and group SIDs are the same.
* Set the more restrictive of the two modes.
-14
View File
@@ -93,18 +93,4 @@ struct owner_group_sids {
struct owner_sid group;
} __packed;
/*
* Minimum security identifier can be one for system defined Users
* and Groups such as NULL SID and World or Built-in accounts such
* as Administrator and Guest and consists of
* Revision + Num (Sub)Auths + Authority + Domain (one Subauthority)
*/
#define MIN_SID_LEN (1 + 1 + 6 + 4) /* in bytes */
/*
* Minimum security descriptor can be one without any SACL and DACL and can
* consist of revision, type, and two sids of minimum size for owner and group
*/
#define MIN_SEC_DESC_LEN (sizeof(struct smb_ntsd) + (2 * MIN_SID_LEN))
#endif /* _CIFSACL_H */
+150 -30
View File
@@ -164,6 +164,7 @@ struct workqueue_struct *cifsoplockd_wq;
struct workqueue_struct *deferredclose_wq;
struct workqueue_struct *serverclose_wq;
struct workqueue_struct *cfid_put_wq;
struct workqueue_struct *cifs_writeback_wq;
__u32 cifs_lock_secret;
/*
@@ -293,9 +294,115 @@ out_no_root:
return rc;
}
struct cifs_tcon_ref {
struct list_head list;
struct tcon_link *tlink;
struct cifs_tcon *tcon;
bool shared;
};
static bool used_by_other_mounts(struct cifs_tcon *tcon,
struct list_head *tcons)
{
struct cifs_tcon_ref *ref;
int n = 0;
list_for_each_entry(ref, tcons, list)
n += ref->tcon == tcon;
guard(spinlock)(&tcon->tc_lock);
return tcon->mnt_refs - tcon->mnt_unlinked > n;
}
static void get_sb_tcons(struct cifs_sb_info *cifs_sb, struct list_head *tcons)
{
struct rb_root *root = &cifs_sb->tlink_tree;
struct cifs_tcon_ref *ref;
struct tcon_link *tlink;
struct cifs_tcon *tcon;
struct rb_node *node;
guard(spinlock)(&cifs_sb->tlink_tree_lock);
for (node = rb_first(root); node; node = rb_next(node)) {
tlink = rb_entry(node, struct tcon_link, tl_rbnode);
tcon = tlink_tcon(tlink);
if (IS_ERR_OR_NULL(tcon))
continue;
ref = kmalloc_obj(struct cifs_tcon_ref, GFP_ATOMIC);
if (!ref)
break;
ref->tlink = cifs_get_tlink(tlink);
ref->tcon = tcon;
list_add_tail(&ref->list, tcons);
}
list_for_each_entry(ref, tcons, list)
ref->shared = used_by_other_mounts(ref->tcon, tcons);
}
static void put_sb_tcons(struct list_head *tcons)
{
struct cifs_tcon_ref *ref, *tmp;
list_for_each_entry_safe(ref, tmp, tcons, list) {
cifs_put_tlink(ref->tlink);
list_del(&ref->list);
kfree(ref);
}
}
/*
* While a forced unmount tears a superblock down, keep its tcons from
* reconnecting or replaying so the teardown (flushing close and oplock work,
* sending the tree disconnect) can't hang on a server that is gone. It is a
* count, not a flag, so a tcon shared with another mount only has its retries
* suppressed for the duration of this teardown; one no mount uses any more
* stays dying until it is freed.
*/
static void set_tcons_dying(struct cifs_sb_info *cifs_sb,
struct list_head *tcons)
{
struct cifs_tcon_ref *ref;
get_sb_tcons(cifs_sb, tcons);
list_for_each_entry(ref, tcons, list) {
atomic_inc(&ref->tcon->dying);
cifs_wake_ses_waiters(ref->tcon->ses);
}
}
static void clear_tcons_dying(struct list_head *tcons)
{
struct cifs_tcon_ref *ref;
flush_workqueue(serverclose_wq);
list_for_each_entry(ref, tcons, list) {
guard(spinlock)(&ref->tcon->tc_lock);
if (ref->tcon->mnt_refs)
atomic_dec(&ref->tcon->dying);
}
put_sb_tcons(tcons);
}
static void cifs_kill_sb(struct super_block *sb)
{
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
LIST_HEAD(tcons);
bool force;
force = atomic_read(&cifs_sb->umount_aborts);
/*
* Reaching here after a umount -f means the mount is going away for
* good, so stop retrying I/O that can no longer complete (e.g.
* writeback to a server that is gone) rather than looping forever on
* a hard mount and hanging the teardown below.
*/
if (force) {
WRITE_ONCE(cifs_sb->exiting, true);
set_tcons_dying(cifs_sb, &tcons);
}
/*
* We need to release all dentries for the cached directories
@@ -329,6 +436,9 @@ static void cifs_kill_sb(struct super_block *sb)
kill_anon_super(sb);
cifs_umount(cifs_sb);
if (force)
clear_tcons_dying(&tcons);
}
static int
@@ -827,46 +937,46 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
return 0;
}
static void abort_reconnect(struct cifs_tcon *tcon)
{
scoped_guard(spinlock, &tcon->tc_lock)
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
netfs_trace_tcon_ref_see_umount);
atomic_inc(&tcon->umount_aborts);
if (tcon->ses && tcon->ses->server) {
cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n");
cifs_wake_ses_waiters(tcon->ses);
msleep(1); /* yield */
/* we have to kick the requests once more */
cifs_wake_ses_waiters(tcon->ses);
msleep(1);
}
}
static void cifs_umount_begin(struct super_block *sb)
{
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifs_tcon *tcon;
struct cifs_tcon_ref *ref;
LIST_HEAD(tcons);
if (cifs_sb == NULL)
return;
tcon = cifs_sb_master_tcon(cifs_sb);
atomic_inc(&cifs_sb->umount_aborts);
spin_lock(&cifs_tcp_ses_lock);
spin_lock(&tcon->tc_lock);
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
netfs_trace_tcon_ref_see_umount);
if ((tcon->tc_count > 1) || (tcon->status == TID_EXITING)) {
/* we have other mounts to same share or we have
already tried to umount this and woken up
all waiting network requests, nothing to do */
spin_unlock(&tcon->tc_lock);
spin_unlock(&cifs_tcp_ses_lock);
return;
}
/*
* can not set tcon->status to TID_EXITING yet since we don't know if umount -f will
* fail later (e.g. due to open files). TID_EXITING will be set just before tdis req sent
* Abort the reconnect waits of the master tcon and of any per-user
* tcons of a multiuser mount that no other mount uses, pinning their
* tlinks so that they stay alive, and aren't pruned, while we abort and
* sleep outside the tree lock.
*/
spin_unlock(&tcon->tc_lock);
spin_unlock(&cifs_tcp_ses_lock);
if (tcon->ses && tcon->ses->server) {
cifs_dbg(FYI, "wake up tasks now - umount begin not complete\n");
wake_up_all(&tcon->ses->server->request_q);
wake_up_all(&tcon->ses->server->response_q);
msleep(1); /* yield */
/* we have to kick the requests once more */
wake_up_all(&tcon->ses->server->response_q);
msleep(1);
get_sb_tcons(cifs_sb, &tcons);
list_for_each_entry(ref, &tcons, list) {
if (!ref->shared)
abort_reconnect(ref->tcon);
}
return;
put_sb_tcons(&tcons);
}
static int cifs_freeze(struct super_block *sb)
@@ -2123,9 +2233,16 @@ init_cifs(void)
goto out_destroy_serverclose_wq;
}
cifs_writeback_wq = alloc_workqueue("cifswritebackd",
WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
if (!cifs_writeback_wq) {
rc = -ENOMEM;
goto out_destroy_cfid_put_wq;
}
rc = cifs_init_inodecache();
if (rc)
goto out_destroy_cfid_put_wq;
goto out_destroy_writeback_wq;
rc = cifs_init_netfs();
if (rc)
@@ -2196,6 +2313,8 @@ out_destroy_netfs:
cifs_destroy_netfs();
out_destroy_inodecache:
cifs_destroy_inodecache();
out_destroy_writeback_wq:
destroy_workqueue(cifs_writeback_wq);
out_destroy_cfid_put_wq:
destroy_workqueue(cfid_put_wq);
out_destroy_serverclose_wq:
@@ -2241,6 +2360,7 @@ exit_cifs(void)
destroy_workqueue(fileinfo_put_wq);
destroy_workqueue(serverclose_wq);
destroy_workqueue(cfid_put_wq);
destroy_workqueue(cifs_writeback_wq);
destroy_workqueue(cifsiod_wq);
}
+49 -1
View File
@@ -585,7 +585,7 @@ struct smb_version_operations {
unsigned int (*wp_retry_size)(struct inode *);
/* get mtu credits */
int (*wait_mtu_credits)(struct TCP_Server_Info *, size_t,
size_t *, struct cifs_credits *);
size_t *, struct cifs_credits *, bool nowait);
/* adjust previously taken mtu credits to request size */
int (*adjust_credits)(struct TCP_Server_Info *server,
struct cifs_io_subrequest *subreq,
@@ -887,6 +887,14 @@ has_credits(struct TCP_Server_Info *server, int *credits, int num_credits)
return num >= num_credits;
}
static inline bool
credits_or_conn_down(struct TCP_Server_Info *server, int *credits,
int num_credits, bool nowait)
{
return has_credits(server, credits, num_credits) ||
(nowait && READ_ONCE(server->tcpStatus) == CifsNeedReconnect);
}
static inline void
add_credits(struct TCP_Server_Info *server, struct cifs_credits *credits,
const int optype)
@@ -1196,6 +1204,10 @@ struct cifs_tcon {
struct list_head tcon_list;
int debug_id; /* Debugging for tracing */
int tc_count;
int mnt_refs; /* refs held by mounts, under tc_lock */
int mnt_unlinked; /* mnt_refs of tlinks being built */
atomic_t umount_aborts; /* nr of umount -f attempts */
atomic_t dying; /* umount -f: stop reconnects/replays */
struct list_head rlist; /* reconnect list */
spinlock_t tc_lock; /* protect anything here that is not protected */
atomic_t num_local_opens; /* num of all opens including disconnected */
@@ -1407,6 +1419,9 @@ struct cifs_open_parms {
umode_t mode;
bool reconnect:1;
bool replay:1; /* indicates that this open is for a replay */
bool no_replay:1; /* don't replay this open internally */
bool pending:1; /* in/out: last built create had no answer */
bool no_reconnect_wait:1; /* fail fast, don't wait for reconnect */
struct kvec *ea_cctx;
__le32 lease_flags;
};
@@ -1458,6 +1473,10 @@ struct cifsFileInfo {
int count;
spinlock_t file_info_lock; /* protects four flag/count fields above */
struct mutex fh_mutex; /* prevents reopen race after dead ses*/
unsigned int reopens;
bool reopen_fresh; /* durable handle gone: reopen opens afresh */
bool reopen_replay; /* reopen replays its last create */
int reopen_access; /* desired access of that create */
struct cifs_search_info srch_inf;
struct work_struct oplock_break; /* work for oplock breaks */
struct work_struct put; /* work for the final part of _put */
@@ -1482,6 +1501,16 @@ struct cifs_io_request {
struct netfs_io_request rreq;
struct cifsFileInfo *cfile;
pid_t pid;
int umount_aborts;
bool reopen_gave_up;
bool replay;
atomic_t bad_reopens; /* 0 or bad gen + 1 */
int reopen_err;
int reopen_pass_err;
struct mutex reopen_lock; /* serializes reopens */
unsigned long retry_deadline;
unsigned int cur_sleep;
unsigned int slept;
};
/* asynchronous read support */
@@ -1496,8 +1525,11 @@ struct cifs_io_subrequest {
int result;
bool have_xid;
bool replay;
bool deferred; /* issue in a worker */
unsigned int reopens;
unsigned int retries; /* number of retries so far */
unsigned int cur_sleep; /* time to sleep before replay */
unsigned long retry_deadline;
struct kvec iov[2];
struct TCP_Server_Info *server;
#ifdef CONFIG_CIFS_SMB_DIRECT
@@ -1891,6 +1923,8 @@ enum cifs_find_flags {
FIND_WITH_DELETE = (1U << 1),
FIND_NO_PENDING_DELETE = (1U << 2),
FIND_OPEN_FLAGS = (1U << 3),
FIND_NO_DIRECT = (1U << 4),
FIND_NO_REOPEN = (1U << 5),
};
#define MID_FREE 0
@@ -1933,6 +1967,7 @@ enum cifs_find_flags {
#define CIFS_COMPRESS_REQ 0x4000 /* compress request before sending */
#define CIFS_INTERRUPTIBLE_WAIT 0x8000 /* Interruptible wait (e.g. lock request) */
#define CIFS_WINDOWS_LOCK 0x10000 /* We're trying to get a Windows lock */
#define CIFS_NO_RECONNECT_WAIT 0x20000 /* don't wait if conn is down */
/* Security Flags: indicate type of session setup needed */
#define CIFSSEC_MAY_SIGN 0x00001
@@ -2141,6 +2176,7 @@ extern struct workqueue_struct *cifsoplockd_wq;
extern struct workqueue_struct *deferredclose_wq;
extern struct workqueue_struct *serverclose_wq;
extern struct workqueue_struct *cfid_put_wq;
extern struct workqueue_struct *cifs_writeback_wq;
extern __u32 cifs_lock_secret;
extern mempool_t *cifs_sm_req_poolp;
@@ -2373,6 +2409,18 @@ static inline void cifs_reset_oplock(struct cifsInodeInfo *cinode)
WRITE_ONCE(cinode->oplock, 0);
}
static inline bool cifs_tcon_dying(struct cifs_tcon *tcon)
{
return atomic_read(&tcon->dying) ||
(!tcon->ipc && !tcon->dummy && !READ_ONCE(tcon->mnt_refs));
}
static inline bool cifs_tcon_retry(struct cifs_tcon *tcon, int aborts)
{
return tcon->retry && atomic_read(&tcon->umount_aborts) == aborts &&
!cifs_tcon_dying(tcon);
}
static inline bool cifs_forced_shutdown(const struct cifs_sb_info *sbi)
{
return cifs_sb_flags(sbi) & CIFS_MOUNT_SHUTDOWN;
+9 -3
View File
@@ -112,7 +112,8 @@ int __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
int wait_for_free_request(struct TCP_Server_Info *server, const int flags,
unsigned int *instance);
int cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
size_t *num, struct cifs_credits *credits);
size_t *num, struct cifs_credits *credits,
bool nowait);
static inline int
send_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server,
@@ -137,6 +138,8 @@ bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file,
bool from_readdir);
void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata,
ssize_t result);
bool cifs_io_stopped(struct cifs_io_subrequest *subreq);
bool cifs_io_should_replay(struct cifs_io_subrequest *subreq);
struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
int flags);
int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode,
@@ -241,7 +244,7 @@ int cifs_match_super(struct super_block *sb, struct fs_context *fc);
int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx);
void cifs_umount(struct cifs_sb_info *cifs_sb);
void cifs_mark_open_files_invalid(struct cifs_tcon *tcon);
void cifs_reopen_persistent_handles(struct cifs_tcon *tcon);
bool cifs_reopen_persistent_handles(struct cifs_tcon *tcon);
bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
__u64 length, __u8 type, __u16 flags,
@@ -440,7 +443,10 @@ static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options)
return options;
}
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry);
void cifs_wake_ses_waiters(struct cifs_ses *ses);
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server,
struct cifs_tcon *tcon, int aborts,
bool nowait);
static inline void cifs_put_smb_ses(struct cifs_ses *ses)
{
+10 -5
View File
@@ -73,6 +73,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
{
struct TCP_Server_Info *server;
struct cifs_ses *ses;
int aborts;
int rc;
/*
@@ -83,6 +84,8 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
if (!tcon)
return 0;
aborts = atomic_read(&tcon->umount_aborts);
ses = tcon->ses;
server = ses->server;
@@ -102,7 +105,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
spin_unlock(&tcon->tc_lock);
again:
rc = cifs_wait_for_server_reconnect(server, tcon->retry);
rc = cifs_wait_for_server_reconnect(server, tcon, aborts, false);
if (rc)
return rc;
@@ -127,7 +130,7 @@ again:
case CifsNeedReconnect:
spin_unlock(&server->srv_lock);
mutex_unlock(&ses->session_mutex);
if (!tcon->retry)
if (!cifs_tcon_retry(tcon, aborts))
return -EHOSTDOWN;
goto again;
default:
@@ -159,7 +162,7 @@ again:
rc = cifs_negotiate_protocol(0, ses, server);
if (rc) {
mutex_unlock(&ses->session_mutex);
if (!tcon->retry)
if (!cifs_tcon_retry(tcon, aborts))
return -EHOSTDOWN;
goto again;
}
@@ -1939,12 +1942,14 @@ cifs_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
break;
case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
if (wdata->rreq->origin != NETFS_WRITEBACK)
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
result = -EAGAIN;
break;
case MID_RETRY_NEEDED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
if (wdata->rreq->origin != NETFS_WRITEBACK)
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
result = -EAGAIN;
break;
case MID_RESPONSE_MALFORMED:
+65 -13
View File
@@ -352,6 +352,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)
mid_execute_callback(server, mid);
release_mid(server, mid);
}
wake_up_all(&server->request_q);
}
static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num_targets)
@@ -2200,7 +2201,8 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
kref_put(&ses->chans[i].iface->refcount, release_iface);
ses->chans[i].iface = NULL;
}
cifs_put_tcp_session(ses->chans[i].server, 0);
if (ses->chans[i].server)
cifs_put_tcp_session(ses->chans[i].server, 0);
ses->chans[i].server = NULL;
}
@@ -2610,18 +2612,21 @@ static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
}
static struct cifs_tcon *
cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx,
bool unlinked)
{
struct cifs_tcon *tcon;
spin_lock(&cifs_tcp_ses_lock);
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
spin_lock(&tcon->tc_lock);
if (!match_tcon(tcon, ctx)) {
if (!match_tcon(tcon, ctx) || cifs_tcon_dying(tcon)) {
spin_unlock(&tcon->tc_lock);
continue;
}
++tcon->tc_count;
++tcon->mnt_refs;
tcon->mnt_unlinked += unlinked;
trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
netfs_trace_tcon_ref_get_find);
spin_unlock(&tcon->tc_lock);
@@ -2695,10 +2700,47 @@ cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace)
#endif
}
void cifs_wake_ses_waiters(struct cifs_ses *ses)
{
guard(spinlock)(&ses->chan_lock);
for (size_t i = 0; i < ses->chan_count; i++) {
struct TCP_Server_Info *server = ses->chans[i].server;
if (!server)
continue;
wake_up_all(&server->request_q);
wake_up_all(&server->response_q);
}
}
static void drop_mnt_ref(struct cifs_tcon *tcon)
{
scoped_guard(spinlock, &tcon->tc_lock) {
if (--tcon->mnt_refs)
return;
}
cifs_wake_ses_waiters(tcon->ses);
}
static void put_mnt_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace)
{
drop_mnt_ref(tcon);
cifs_put_tcon(tcon, trace);
}
static void erase_tlink(struct cifs_sb_info *cifs_sb, struct tcon_link *tlink)
{
clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
rb_erase(&tlink->tl_rbnode, &cifs_sb->tlink_tree);
if (!IS_ERR(tlink_tcon(tlink)))
drop_mnt_ref(tlink_tcon(tlink));
}
/**
* cifs_get_tcon - get a tcon matching @ctx data from @ses
* @ses: smb session to issue the request on
* @ctx: the superblock configuration context to use for building the
* @unlinked: the mount reference is for a tlink not yet in a superblock's tree
*
* - tcon refcount is the number of mount points using the tcon.
* - ses refcount is the number of tcon using the session.
@@ -2718,13 +2760,13 @@ cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace)
* decrement the ses refcount.
*/
static struct cifs_tcon *
cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx, bool unlinked)
{
struct cifs_tcon *tcon;
bool nohandlecache;
int rc, xid;
tcon = cifs_find_tcon(ses, ctx);
tcon = cifs_find_tcon(ses, ctx, unlinked);
if (tcon) {
/*
* tcon has refcount already incremented but we need to
@@ -2750,6 +2792,8 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
rc = -ENOMEM;
goto out_fail;
}
tcon->mnt_refs = 1;
tcon->mnt_unlinked = unlinked;
tcon->nohandlecache = nohandlecache;
if (ctx->snapshot_time) {
@@ -3576,7 +3620,7 @@ void cifs_mount_put_conns(struct cifs_mount_ctx *mnt_ctx)
int rc = 0;
if (mnt_ctx->tcon)
cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx);
put_mnt_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx);
else if (mnt_ctx->ses)
cifs_put_smb_ses(mnt_ctx->ses);
else if (mnt_ctx->server)
@@ -3656,7 +3700,7 @@ int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx)
cifs_sb = mnt_ctx->cifs_sb;
/* search for existing tcon to this server share */
tcon = cifs_get_tcon(mnt_ctx->ses, ctx);
tcon = cifs_get_tcon(mnt_ctx->ses, ctx, false);
if (IS_ERR(tcon)) {
rc = PTR_ERR(tcon);
tcon = NULL;
@@ -4032,8 +4076,7 @@ cifs_umount(struct cifs_sb_info *cifs_sb)
while ((node = rb_first(root))) {
tlink = rb_entry(node, struct tcon_link, tl_rbnode);
cifs_get_tlink(tlink);
clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
rb_erase(node, root);
erase_tlink(cifs_sb, tlink);
spin_unlock(&cifs_sb->tlink_tree_lock);
cifs_put_tlink(tlink);
@@ -4321,7 +4364,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
}
#endif
tcon = cifs_get_tcon(ses, ctx);
tcon = cifs_get_tcon(ses, ctx, true);
if (IS_ERR(tcon)) {
cifs_put_smb_ses(ses);
goto out;
@@ -4424,6 +4467,7 @@ cifs_sb_tlink(struct cifs_sb_info *cifs_sb)
{
struct tcon_link *tlink, *newtlink;
kuid_t fsuid = current_fsuid();
struct cifs_tcon *tcon;
int err;
if (!(cifs_sb_flags(cifs_sb) & CIFS_MOUNT_MULTIUSER))
@@ -4481,7 +4525,16 @@ wait_for_construction:
goto wait_for_construction;
}
tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid);
tcon = cifs_construct_tcon(cifs_sb, fsuid);
scoped_guard(spinlock, &cifs_sb->tlink_tree_lock) {
tlink->tl_tcon = tcon;
if (!IS_ERR(tcon)) {
scoped_guard(spinlock, &tcon->tc_lock)
tcon->mnt_unlinked--;
if (!test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags))
drop_mnt_ref(tcon);
}
}
clear_bit(TCON_LINK_PENDING, &tlink->tl_flags);
wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING);
@@ -4530,8 +4583,7 @@ cifs_prune_tlinks(struct work_struct *work)
continue;
cifs_get_tlink(tlink);
clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags);
rb_erase(tmp, root);
erase_tlink(cifs_sb, tlink);
spin_unlock(&cifs_sb->tlink_tree_lock);
cifs_put_tlink(tlink);
+6 -6
View File
@@ -33,7 +33,7 @@ int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_para
if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0))
return -EINVAL;
if (strlen(full_path) - ref->path_consumed) {
if ((size_t)ref->path_consumed < strlen(full_path)) {
prepath = full_path + ref->path_consumed;
/* skip initial delimiter */
if (*prepath == '/' || *prepath == '\\')
@@ -103,6 +103,7 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw)
struct cifs_sb_info *cifs_sb = rw->mnt_ctx->cifs_sb;
struct smb3_fs_context *ctx = rw->mnt_ctx->fs_ctx;
char *ref_path, *full_path;
const char *raw_path;
int rc;
set_root_smb_session(rw->mnt_ctx);
@@ -114,9 +115,10 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw)
if (!tgt || (tgt->server_type == DFS_TYPE_LINK &&
DFS_INTERLINK(tgt->flags)))
ref_path = dfs_get_path(cifs_sb, ctx->UNC);
raw_path = ctx->UNC;
else
ref_path = dfs_get_path(cifs_sb, full_path);
raw_path = full_path;
ref_path = dfs_get_path(cifs_sb, raw_path);
if (IS_ERR(ref_path)) {
rc = PTR_ERR(ref_path);
kfree(full_path);
@@ -125,9 +127,7 @@ static int setup_dfs_ref(struct dfs_info3_param *tgt, struct dfs_ref_walk *rw)
ref_walk_path(rw) = ref_path;
ref_walk_fpath(rw) = full_path;
return dfs_get_referral(rw->mnt_ctx,
ref_walk_path(rw) + 1,
ref_walk_tl(rw));
return dfs_get_referral(rw->mnt_ctx, raw_path + 1, ref_walk_tl(rw));
}
static int __dfs_referral_walk(struct dfs_ref_walk *rw)
+624 -45
View File
@@ -37,7 +37,261 @@
#include "cached_dir.h"
#include <trace/events/netfs.h>
static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush);
/* flags for cifs_reopen_file() */
#define CIFS_REOPEN_BOUND BIT(0) /* caller bounds the retries */
#define CIFS_REOPEN_NOWAIT BIT(1) /* fail fast, skip reconnect wait */
static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush,
unsigned int flags);
bool cifs_io_stopped(struct cifs_io_subrequest *subreq)
{
struct super_block *sb = subreq->rreq->inode->i_sb;
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
int aborts;
if (cifs_forced_shutdown(cifs_sb) || READ_ONCE(cifs_sb->exiting))
return true;
aborts = atomic_read(&cifs_sb->umount_aborts);
if (aborts != subreq->req->umount_aborts)
return true;
return aborts && rwsem_is_contended(&sb->s_umount);
}
static bool cifs_writeback_retry_expired(struct cifs_io_subrequest *subreq,
struct cifs_tcon *tcon)
{
struct TCP_Server_Info *server = tcon->ses->server;
unsigned long window;
if (tcon->retry)
return false;
if (!subreq->retry_deadline) {
window = max(3U, server->retrans) * server->echo_interval;
subreq->retry_deadline = (jiffies + window) | 1;
}
return time_after(jiffies, subreq->retry_deadline);
}
bool cifs_io_should_replay(struct cifs_io_subrequest *subreq)
{
struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink);
if (cifs_io_stopped(subreq))
return false;
if (subreq->rreq->origin == NETFS_WRITEBACK) {
if (cifs_writeback_retry_expired(subreq, tcon))
return false;
smb2_replay_backoff(&subreq->cur_sleep);
return true;
}
return smb2_should_replay(tcon, &subreq->retries, &subreq->cur_sleep);
}
static bool cifs_io_aborted(struct cifs_io_subrequest *subreq)
{
struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink);
if (!cifs_io_stopped(subreq))
return false;
return subreq->subreq.retry_count || subreq->replay ||
READ_ONCE(subreq->server->tcpStatus) == CifsNeedReconnect ||
tcon->need_reconnect;
}
static bool cifs_writeback_transient(int rc)
{
if (is_replayable_error(rc) || is_interrupt_error(rc))
return true;
switch (rc) {
case -ENOMEM:
case -EHOSTDOWN:
case -ENETRESET:
case -ESHUTDOWN:
case -EREMCHG:
case -EBADF:
return true;
}
return false;
}
static int cifs_writeback_error(struct netfs_io_subrequest *subreq, int rc)
{
if (subreq->rreq->origin == NETFS_WRITEBACK &&
cifs_writeback_transient(rc))
return -EIO;
return rc;
}
static bool cifs_writeback_dying(struct netfs_io_subrequest *subreq)
{
return subreq->rreq->origin == NETFS_WRITEBACK &&
fatal_signal_pending(current);
}
static unsigned int cifs_ses_reconnects(struct cifs_ses *ses)
{
unsigned int n = 0;
guard(spinlock)(&ses->chan_lock);
for (size_t i = 0; i < ses->chan_count; i++) {
struct TCP_Server_Info *server = ses->chans[i].server;
if (server)
n += READ_ONCE(server->reconnect_instance);
}
return n;
}
static bool cifs_tcon_reconnecting(struct cifs_tcon *tcon)
{
struct cifs_ses *ses = tcon->ses;
if (tcon->need_reconnect)
return true;
guard(spinlock)(&ses->chan_lock);
for (size_t i = 0; i < ses->chan_count; i++) {
struct TCP_Server_Info *server = ses->chans[i].server;
if (server && READ_ONCE(server->tcpStatus) == CifsNeedReconnect)
return true;
}
return false;
}
static int cifs_reopen_file_retry(struct cifsFileInfo *cfile, bool can_flush,
struct cifs_io_subrequest *subreq)
{
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
struct cifs_ses *ses = tcon->ses;
unsigned int reconnects;
bool free_retry = true;
bool retrying = false;
int rc;
for (;;) {
if ((retrying && cifs_io_stopped(subreq)) ||
cifs_io_aborted(subreq))
return -EIO;
retrying = true;
reconnects = cifs_ses_reconnects(ses);
rc = cifs_reopen_file(cfile, can_flush, CIFS_REOPEN_BOUND);
if (!rc || !is_replayable_error(rc))
return rc;
if (free_retry && !cifs_io_stopped(subreq) &&
(cifs_ses_reconnects(ses) != reconnects ||
cifs_tcon_reconnecting(tcon))) {
free_retry = false;
continue;
}
if (!cifs_io_should_replay(subreq))
return rc;
msleep(subreq->cur_sleep);
}
}
/*
* Record, as generation + 1 (0 means none), the newest reopen generation of a
* handle that a writeback subrequest found bad (-EBADF). Subrequests of the
* same request can fail concurrently on different channels, so keep the newest.
*/
static void cifs_mark_bad_handle(struct cifs_io_request *req, unsigned int gen)
{
int cur = atomic_read(&req->bad_reopens);
int want = gen + 1;
while (want > cur && !atomic_try_cmpxchg(&req->bad_reopens, &cur, want))
;
}
static bool cifs_bad_handle_pending(struct cifs_io_request *req)
{
unsigned int bad = atomic_read(&req->bad_reopens);
return bad && bad - 1 == READ_ONCE(req->cfile->reopens);
}
static void __cifs_invalidate_bad_handle(struct cifs_io_request *req)
{
unsigned int bad = atomic_read(&req->bad_reopens);
struct cifsFileInfo *cfile = req->cfile;
lockdep_assert_held(&cfile->fh_mutex);
if (bad && bad - 1 == cfile->reopens)
cfile->invalidHandle = true;
}
static void cifs_invalidate_bad_handle(struct cifs_io_request *req)
{
if (!cifs_bad_handle_pending(req))
return;
guard(mutex)(&req->cfile->fh_mutex);
__cifs_invalidate_bad_handle(req);
}
static bool cifs_try_invalidate_bad_handle(struct cifs_io_request *req)
{
if (!cifs_bad_handle_pending(req))
return true;
if (!mutex_trylock(&req->cfile->fh_mutex))
return false;
__cifs_invalidate_bad_handle(req);
mutex_unlock(&req->cfile->fh_mutex);
return true;
}
static int cifs_reopen_failed(struct cifs_io_request *req)
{
if (READ_ONCE(req->reopen_gave_up))
return -EIO;
return READ_ONCE(req->reopen_err);
}
static int cifs_reopen_writeback(struct cifs_io_subrequest *wdata)
{
struct cifs_io_request *req = wdata->req;
struct cifsFileInfo *cfile = req->cfile;
int rc;
if (cifs_io_aborted(wdata))
return -EIO;
guard(mutex)(&req->reopen_lock);
if (!cifs_bad_handle_pending(req) && !cfile->invalidHandle)
return 0;
rc = cifs_reopen_failed(req);
if (rc)
return rc;
rc = req->reopen_pass_err;
if (!rc) {
if (!cifs_try_invalidate_bad_handle(req))
rc = -EAGAIN;
else if (cfile->invalidHandle)
rc = cifs_reopen_file(cfile, false,
CIFS_REOPEN_BOUND |
CIFS_REOPEN_NOWAIT);
if (!rc)
return 0;
if (!cifs_writeback_transient(rc)) {
WRITE_ONCE(req->reopen_err, rc);
return rc;
}
req->reopen_pass_err = rc;
}
if (!cifs_io_should_replay(wdata)) {
WRITE_ONCE(req->reopen_gave_up, true);
return -EIO;
}
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
return rc;
}
/*
* Prepare a subrequest to upload to the server. We need to allocate credits
@@ -52,6 +306,8 @@ static void cifs_prepare_write(struct netfs_io_subrequest *subreq)
struct TCP_Server_Info *server;
struct cifsFileInfo *open_file = req->cfile;
struct cifs_sb_info *cifs_sb = CIFS_SB(wdata->rreq->inode->i_sb);
bool writeback = subreq->rreq->origin == NETFS_WRITEBACK;
bool reprepared = wdata->have_xid;
size_t wsize = req->rreq.wsize;
int rc;
@@ -62,29 +318,68 @@ static void cifs_prepare_write(struct netfs_io_subrequest *subreq)
server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses);
wdata->server = server;
wdata->deferred = false;
if (reprepared) {
req->retry_deadline = wdata->retry_deadline;
req->cur_sleep = wdata->cur_sleep;
req->replay = wdata->replay;
} else if (subreq->retry_count) {
wdata->retry_deadline = req->retry_deadline;
wdata->cur_sleep = req->cur_sleep;
wdata->replay = req->replay;
}
if (cifs_io_aborted(wdata) ||
(reprepared && cifs_io_stopped(wdata))) {
subreq->error = -EIO;
return netfs_prepare_write_failed(subreq);
}
if (cifs_sb->ctx->wsize == 0)
cifs_negotiate_wsize(server, cifs_sb->ctx,
tlink_tcon(req->cfile->tlink));
retry:
if (open_file->invalidHandle) {
rc = cifs_reopen_file(open_file, false);
if (rc < 0) {
if (rc == -EAGAIN)
goto retry;
if (writeback &&
(cifs_bad_handle_pending(req) || open_file->invalidHandle)) {
rc = cifs_reopen_failed(req);
if (rc) {
subreq->error = rc;
return netfs_prepare_write_failed(subreq);
}
goto defer;
}
if (cifs_writeback_dying(subreq))
goto defer;
if (!writeback) {
cifs_invalidate_bad_handle(req);
if (open_file->invalidHandle) {
rc = cifs_reopen_file_retry(open_file, false, wdata);
if (rc < 0) {
subreq->error = rc;
return netfs_prepare_write_failed(subreq);
}
}
}
rc = server->ops->wait_mtu_credits(server, wsize, &stream->sreq_max_len,
&wdata->credits);
&wdata->credits, writeback);
if (rc < 0) {
subreq->error = rc;
if (cifs_writeback_dying(subreq) ||
(writeback && rc == -EAGAIN))
goto defer;
subreq->error = cifs_writeback_error(subreq, rc);
return netfs_prepare_write_failed(subreq);
}
goto out;
defer:
wdata->deferred = true;
wdata->credits = (struct cifs_credits){};
stream->sreq_max_len = min_t(size_t, wsize, SMB2_MAX_BUFFER_SIZE);
out:
wdata->credits.rreq_debug_id = subreq->rreq->debug_id;
wdata->credits.rreq_debug_index = subreq->debug_index;
wdata->credits.in_flight_check = 1;
@@ -108,7 +403,7 @@ retry:
/*
* Issue a subrequest to upload to the server.
*/
static void cifs_issue_write(struct netfs_io_subrequest *subreq)
static void __cifs_issue_write(struct netfs_io_subrequest *subreq)
{
struct cifs_io_subrequest *wdata =
container_of(subreq, struct cifs_io_subrequest, subreq);
@@ -120,28 +415,142 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq)
goto fail;
}
rc = -EIO;
if (cifs_io_aborted(wdata))
goto fail;
rc = adjust_credits(wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust);
if (rc)
goto fail;
rc = -EAGAIN;
if (wdata->req->cfile->invalidHandle)
if (wdata->req->cfile->invalidHandle ||
(wdata->credits.value &&
wdata->credits.instance !=
READ_ONCE(wdata->server->reconnect_instance)))
goto fail;
/* pairs with smp_store_release() in cifs_reopen_file() */
wdata->reopens = smp_load_acquire(&wdata->req->cfile->reopens);
wdata->server->ops->async_writev(wdata);
out:
return;
fail:
if (rc == -EAGAIN)
if (rc == -EAGAIN) {
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
else
__set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
} else {
trace_netfs_sreq(subreq, netfs_sreq_trace_fail);
}
add_credits_and_wake_if(wdata->server, &wdata->credits, 0);
cifs_write_subrequest_terminated(wdata, rc);
goto out;
}
static void cifs_issue_write_worker(struct work_struct *work)
{
struct cifs_io_subrequest *wdata;
struct cifsFileInfo *cfile;
int rc = 0;
wdata = container_of(work, struct cifs_io_subrequest, subreq.work);
cfile = wdata->req->cfile;
if (cifs_bad_handle_pending(wdata->req) || cfile->invalidHandle)
rc = cifs_reopen_writeback(wdata);
if (rc) {
add_credits_and_wake_if(wdata->server, &wdata->credits, 0);
cifs_write_subrequest_terminated(wdata, rc);
return;
}
__cifs_issue_write(&wdata->subreq);
}
static void cifs_issue_write(struct netfs_io_subrequest *subreq)
{
struct cifs_io_subrequest *wdata =
container_of(subreq, struct cifs_io_subrequest, subreq);
struct cifs_io_request *req = wdata->req;
if (wdata->cur_sleep > req->slept) {
msleep(wdata->cur_sleep - req->slept);
req->slept = wdata->cur_sleep;
}
if (unlikely(wdata->deferred || cifs_writeback_dying(subreq))) {
subreq->work.func = cifs_issue_write_worker;
WARN_ON_ONCE(!queue_work(cifs_writeback_wq, &subreq->work));
return;
}
__cifs_issue_write(subreq);
}
static void cifs_share_retry_state(struct netfs_io_subrequest *from,
struct netfs_io_subrequest *stop,
struct list_head *head)
{
struct netfs_io_subrequest *subreq = from;
struct cifs_io_subrequest *wdata;
unsigned long deadline = 0;
unsigned int sleep = 0;
bool replay = false;
list_for_each_entry_from(subreq, head, rreq_link) {
if (subreq == stop)
break;
wdata = container_of(subreq, struct cifs_io_subrequest, subreq);
if (wdata->retry_deadline &&
(!deadline || time_before(wdata->retry_deadline, deadline)))
deadline = wdata->retry_deadline;
sleep = max(sleep, wdata->cur_sleep);
replay |= wdata->replay;
}
subreq = from;
list_for_each_entry_from(subreq, head, rreq_link) {
if (subreq == stop)
break;
wdata = container_of(subreq, struct cifs_io_subrequest, subreq);
wdata->retry_deadline = deadline;
wdata->cur_sleep = sleep;
wdata->replay = replay;
}
}
static void cifs_retry_request(struct netfs_io_request *wreq,
struct netfs_io_stream *stream)
{
struct netfs_io_subrequest *subreq, *from = NULL;
struct cifs_io_request *req =
container_of(wreq, struct cifs_io_request, rreq);
uoff_t end = 0;
req->slept = 0;
req->reopen_pass_err = 0;
if (!stream)
return;
guard(spinlock)(&wreq->lock);
list_for_each_entry(subreq, &stream->subrequests, rreq_link) {
if (from && test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags) &&
!test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) &&
subreq->start + subreq->transferred == end) {
end += subreq->len;
continue;
}
if (from)
cifs_share_retry_state(from, subreq,
&stream->subrequests);
from = NULL;
if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
from = subreq;
end = subreq->start + subreq->len;
}
}
if (from)
cifs_share_retry_state(from, NULL, &stream->subrequests);
}
static void cifs_netfs_invalidate_cache(struct netfs_io_request *wreq)
{
cifs_invalidate_cache(wreq->inode, 0);
@@ -157,6 +566,7 @@ static int cifs_prepare_read(struct netfs_io_subrequest *subreq)
struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq);
struct TCP_Server_Info *server;
struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb);
bool reprepared = rdata->have_xid;
size_t size;
int rc = 0;
@@ -168,12 +578,22 @@ static int cifs_prepare_read(struct netfs_io_subrequest *subreq)
server = cifs_pick_channel(tlink_tcon(req->cfile->tlink)->ses);
rdata->server = server;
if (cifs_io_aborted(rdata) ||
(reprepared && cifs_io_stopped(rdata)))
return -EIO;
if (cifs_sb->ctx->rsize == 0)
cifs_negotiate_rsize(server, cifs_sb->ctx,
tlink_tcon(req->cfile->tlink));
if (req->cfile->invalidHandle) {
rc = cifs_reopen_file_retry(req->cfile, true, rdata);
if (rc)
return rc;
}
rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize,
&size, &rdata->credits);
&size, &rdata->credits, false);
if (rc)
return rc;
@@ -218,18 +638,27 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq)
__func__, rreq->debug_id, subreq->debug_index, rreq->mapping,
subreq->transferred, subreq->len);
rc = adjust_credits(server, rdata, cifs_trace_rw_credits_issue_read_adjust);
if (rc)
rc = -EIO;
if (cifs_io_aborted(rdata))
goto failed;
if (req->cfile->invalidHandle) {
do {
rc = cifs_reopen_file(req->cfile, true);
} while (rc == -EAGAIN);
if (rc)
rc = adjust_credits(server, rdata, cifs_trace_rw_credits_issue_read_adjust);
if (rc)
goto not_sent;
if (rdata->replay && rdata->cur_sleep) {
msleep(rdata->cur_sleep);
rc = -EIO;
if (cifs_io_aborted(rdata))
goto failed;
}
rc = -EAGAIN;
if (req->cfile->invalidHandle ||
(rdata->credits.value &&
rdata->credits.instance != READ_ONCE(server->reconnect_instance)))
goto not_sent;
if (subreq->rreq->origin != NETFS_UNBUFFERED_READ &&
subreq->rreq->origin != NETFS_DIO_READ)
__set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);
@@ -240,6 +669,11 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq)
goto failed;
return;
not_sent:
if (rc == -EAGAIN) {
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
__set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
}
failed:
add_credits_and_wake_if(rdata->server, &rdata->credits, 0);
subreq->error = rc;
@@ -255,9 +689,17 @@ static void cifs_begin_writeback(struct netfs_io_request *wreq)
struct cifs_io_request *req = container_of(wreq, struct cifs_io_request, rreq);
int ret;
ret = cifs_get_writable_file(CIFS_I(wreq->inode), FIND_ANY, &req->cfile);
ret = cifs_get_writable_file(CIFS_I(wreq->inode),
FIND_NO_REOPEN | FIND_NO_DIRECT,
&req->cfile);
if (ret) {
cifs_dbg(VFS, "No writable handle in writepages ret=%d\n", ret);
ret = cifs_get_writable_file(CIFS_I(wreq->inode),
FIND_NO_REOPEN, &req->cfile);
}
if (ret) {
cifs_dbg(VFS, "%s: couldn't find writable handle: %d\n",
__func__, ret);
mapping_set_error(wreq->mapping, -EIO);
return;
}
@@ -276,6 +718,8 @@ static int cifs_init_request(struct netfs_io_request *rreq, struct file *file)
rreq->rsize = cifs_sb->ctx->rsize;
rreq->wsize = cifs_sb->ctx->wsize;
req->pid = current->tgid; // Ummm... This may be a workqueue
req->umount_aborts = atomic_read(&cifs_sb->umount_aborts);
mutex_init(&req->reopen_lock);
if (file) {
open_file = file->private_data;
@@ -364,6 +808,7 @@ const struct netfs_request_ops cifs_req_ops = {
.begin_writeback = cifs_begin_writeback,
.prepare_write = cifs_prepare_write,
.issue_write = cifs_issue_write,
.retry_request = cifs_retry_request,
.invalidate_cache = cifs_netfs_invalidate_cache,
};
@@ -1274,8 +1719,18 @@ cifs_relock_file(struct cifsFileInfo *cfile)
return rc;
}
static bool reopen_aborted(struct cifs_tcon *tcon, int aborts)
{
struct TCP_Server_Info *server;
if (atomic_read(&tcon->umount_aborts) == aborts)
return false;
server = cifs_pick_channel(tcon->ses);
return server && READ_ONCE(server->tcpStatus) == CifsNeedReconnect;
}
static int
cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush, unsigned int flags)
{
int rc = -EACCES;
unsigned int xid;
@@ -1292,18 +1747,31 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
int create_options = CREATE_NOT_DIR;
struct cifs_open_parms oparms;
int rdwr_for_fscache = 0;
int aborts;
bool fresh;
tcon = tlink_tcon(cfile->tlink);
aborts = atomic_read(&tcon->umount_aborts);
xid = get_xid();
mutex_lock(&cfile->fh_mutex);
if (!(flags & CIFS_REOPEN_NOWAIT)) {
mutex_lock(&cfile->fh_mutex);
} else if (!mutex_trylock(&cfile->fh_mutex)) {
free_xid(xid);
return -EAGAIN;
}
if (!cfile->invalidHandle) {
mutex_unlock(&cfile->fh_mutex);
free_xid(xid);
return 0;
}
if (reopen_aborted(tcon, aborts)) {
mutex_unlock(&cfile->fh_mutex);
free_xid(xid);
return -EHOSTDOWN;
}
inode = d_inode(cfile->dentry);
cifs_sb = CIFS_SB(inode->i_sb);
tcon = tlink_tcon(cfile->tlink);
server = tcon->ses->server;
/*
@@ -1359,6 +1827,10 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
if (cifs_fscache_enabled(inode) && (cfile->f_flags & O_ACCMODE) == O_WRONLY)
rdwr_for_fscache = 1;
if (cfile->reopen_replay && rdwr_for_fscache == 1 &&
!(cfile->reopen_access & GENERIC_READ))
rdwr_for_fscache = 2;
desired_access = cifs_convert_flags(cfile->f_flags, rdwr_for_fscache);
create_options |= cifs_open_create_options(cfile->f_flags,
create_options);
@@ -1367,15 +1839,21 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
server->ops->get_lease_key(inode, &cfile->fid);
retry_open:
fresh = cfile->reopen_fresh;
oparms = (struct cifs_open_parms) {
.tcon = tcon,
.cifs_sb = cifs_sb,
.desired_access = desired_access,
.desired_access = cfile->reopen_replay ?
cfile->reopen_access : desired_access,
.create_options = cifs_create_options(cifs_sb, create_options),
.disposition = disposition,
.path = full_path,
.fid = &cfile->fid,
.reconnect = true,
.reconnect = !fresh,
.replay = cfile->reopen_replay,
.pending = cfile->reopen_replay,
.no_replay = !!(flags & CIFS_REOPEN_BOUND),
.no_reconnect_wait = !!(flags & CIFS_REOPEN_NOWAIT),
};
/*
@@ -1385,14 +1863,28 @@ retry_open:
* version of file size can be stale. If we knew for sure that inode was
* not dirty locally we could do this.
*/
rc = server->ops->open(xid, &oparms, &oplock, NULL);
if (rc == -ENOENT && oparms.reconnect == false) {
/* durable handle timeout is expired - open the file again */
if (reopen_aborted(tcon, aborts))
rc = -EHOSTDOWN;
else
rc = server->ops->open(xid, &oparms, &oplock, NULL);
/* indicate that we need to relock the file */
oparms.reconnect = true;
if (rc == -ENOENT && !fresh && !oparms.reconnect && !oparms.pending) {
/* durable handle timeout is expired - open the file again */
fresh = true;
oparms.desired_access = desired_access;
oparms.replay = false;
if (reopen_aborted(tcon, aborts))
rc = -EHOSTDOWN;
else
rc = server->ops->open(xid, &oparms, &oplock, NULL);
}
if (rc == -EACCES && rdwr_for_fscache == 1) {
cfile->reopen_fresh = rc && fresh;
cfile->reopen_replay = rc && oparms.pending;
if (cfile->reopen_replay)
cfile->reopen_access = oparms.desired_access;
/* indicate that we need to relock the file */
if (fresh)
oparms.reconnect = true;
if (rc == -EACCES && rdwr_for_fscache == 1 && !oparms.pending) {
desired_access = cifs_convert_flags(cfile->f_flags, 0);
rdwr_for_fscache = 2;
goto retry_open;
@@ -1411,6 +1903,8 @@ retry_open:
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
reopen_success:
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* pairs with smp_load_acquire() in __cifs_issue_write() */
smp_store_release(&cfile->reopens, cfile->reopens + 1);
cfile->invalidHandle = false;
mutex_unlock(&cfile->fh_mutex);
cinode = CIFS_I(inode);
@@ -1546,14 +2040,16 @@ int cifs_close(struct inode *inode, struct file *file)
return 0;
}
void
bool
cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
{
struct cifsFileInfo *open_file, *tmp;
LIST_HEAD(tmp_list);
bool retry = false;
int rc;
if (!tcon->use_persistent || !tcon->need_reopen_files)
return;
return false;
tcon->need_reopen_files = false;
@@ -1570,11 +2066,17 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
spin_unlock(&tcon->open_file_lock);
list_for_each_entry_safe(open_file, tmp, &tmp_list, rlist) {
if (cifs_reopen_file(open_file, false /* do not flush */))
/* do not flush */
rc = cifs_reopen_file(open_file, false,
CIFS_REOPEN_BOUND | CIFS_REOPEN_NOWAIT);
if (rc) {
tcon->need_reopen_files = true;
retry |= is_replayable_error(rc);
}
list_del_init(&open_file->rlist);
cifsFileInfo_put(open_file);
}
return retry;
}
int cifs_closedir(struct inode *inode, struct file *file)
@@ -2235,7 +2737,7 @@ cifs_get_hardlink_path(struct cifs_tcon *tcon, struct inode *inode,
spin_lock(&cinode->open_file_lock);
list_for_each_entry(open_file, &cinode->openFileList, flist) {
if (file->f_flags == open_file->f_flags) {
if (open_file->dentry != file_dentry(file)) {
rc = -EINVAL;
break;
}
@@ -2629,6 +3131,20 @@ void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t
spin_unlock(&inode->i_lock);
}
if (wreq->origin == NETFS_WRITEBACK &&
!test_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags) &&
cifs_writeback_transient(result) && cifs_io_should_replay(wdata)) {
if (result == -EBADF)
cifs_mark_bad_handle(wdata->req, wdata->reopens);
wdata->replay = true;
trace_netfs_sreq(&wdata->subreq,
netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
}
if (result < 0 &&
!test_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags))
result = cifs_writeback_error(&wdata->subreq, result);
netfs_write_subrequest_terminated(&wdata->subreq, result);
}
@@ -2722,7 +3238,7 @@ int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode,
}
if (test_bit(CIFS_INO_TMPFILE, &cifs_inode->flags))
find_flags = FIND_ANY;
find_flags &= FIND_NO_REOPEN | FIND_NO_DIRECT;
cifs_sb = CIFS_SB(cifs_inode);
@@ -2752,6 +3268,9 @@ refind_writable:
!open_flags_match(cifs_inode, open_flags,
open_file->f_flags))
continue;
if ((find_flags & FIND_NO_DIRECT) &&
(open_file->f_flags & O_DIRECT))
continue;
if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) {
if (!open_file->invalidHandle) {
/* found a good writable file */
@@ -2779,7 +3298,11 @@ refind_writable:
spin_unlock(&cifs_inode->open_file_lock);
if (inv_file) {
rc = cifs_reopen_file(inv_file, false);
if (find_flags & FIND_NO_REOPEN) {
*ret_file = inv_file;
return 0;
}
rc = cifs_reopen_file(inv_file, false, 0);
if (!rc) {
*ret_file = inv_file;
return 0;
@@ -2880,6 +3403,45 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
return -ENOENT;
}
static int cifs_wait_writeback_killable(struct address_space *mapping,
loff_t start, loff_t end)
{
pgoff_t end_index = end >> PAGE_SHIFT;
pgoff_t index = start >> PAGE_SHIFT;
struct folio_batch fbatch;
int rc = 0;
folio_batch_init(&fbatch);
while (!rc &&
filemap_get_folios_tag(mapping, &index, end_index,
PAGECACHE_TAG_WRITEBACK, &fbatch)) {
for (unsigned int i = 0;
!rc && i < folio_batch_count(&fbatch); i++)
rc = folio_wait_writeback_killable(fbatch.folios[i]);
folio_batch_release(&fbatch);
cond_resched();
}
return rc;
}
static int cifs_file_write_and_wait_killable(struct file *file,
loff_t start, loff_t end)
{
struct address_space *mapping = file->f_mapping;
int rc, rc2;
if (end < start)
return 0;
rc = filemap_fdatawrite_range(mapping, start, end);
if (cifs_wait_writeback_killable(mapping, start, end))
return -EINTR;
rc2 = file_check_and_advance_wb_err(file);
if (!rc)
rc = rc2;
return rc;
}
/*
* Flush data on a strict file.
*/
@@ -2891,7 +3453,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
unsigned int xid;
int rc;
rc = file_write_and_wait_range(file, start, end);
rc = cifs_file_write_and_wait_killable(file, start, end);
if (rc) {
trace_cifs_fsync_err(inode->i_ino, rc);
return rc;
@@ -2923,7 +3485,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
struct inode *inode = file_inode(file);
struct cifs_sb_info *cifs_sb = CIFS_SB(file);
rc = file_write_and_wait_range(file, start, end);
rc = cifs_file_write_and_wait_killable(file, start, end);
if (rc) {
trace_cifs_fsync_err(file_inode(file)->i_ino, rc);
return rc;
@@ -2964,11 +3526,19 @@ fsync_exit:
*/
int cifs_flush(struct file *file, fl_owner_t id)
{
struct address_space *mapping = file->f_mapping;
struct inode *inode = file_inode(file);
int rc = 0;
int rc = 0, rc2;
if (file->f_mode & FMODE_WRITE)
rc = filemap_write_and_wait(inode->i_mapping);
if (file->f_mode & FMODE_WRITE) {
rc = filemap_fdatawrite(mapping);
if (fatal_signal_pending(current) ||
cifs_wait_writeback_killable(mapping, 0, LLONG_MAX))
return 0;
rc2 = filemap_check_errors(mapping);
if (!rc)
rc = rc2;
}
cifs_dbg(FYI, "Flush inode %p file %p rc %d\n", inode, file, rc);
if (rc) {
@@ -3357,6 +3927,14 @@ void cifs_oplock_break(struct work_struct *work)
__u64 persistent_fid, volatile_fid;
__u16 net_fid;
/*
* Dropping the handle reference below also drops the dentry
* reference that pins this inode, and cinode is still needed to
* acknowledge the break and to report it as complete. Hold the inode
* until that is done.
*/
ihold(inode);
wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS,
TASK_UNINTERRUPTIBLE);
@@ -3444,6 +4022,7 @@ oplock_break_ack:
cifs_put_tlink(tlink);
out:
cifs_done_oplock_break(cinode);
iput(inode);
}
#ifdef CONFIG_SWAP
+19 -3
View File
@@ -1073,7 +1073,17 @@ int cifs_inval_name_dfs_link_error(const unsigned int xid,
}
#endif
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry)
static bool reco_wait_done(struct TCP_Server_Info *server,
struct cifs_tcon *tcon, int aborts)
{
return server->tcpStatus != CifsNeedReconnect ||
atomic_read(&tcon->umount_aborts) != aborts ||
cifs_tcon_dying(tcon);
}
int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server,
struct cifs_tcon *tcon, int aborts,
bool nowait)
{
int timeout = 10;
int rc;
@@ -1083,6 +1093,10 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry)
spin_unlock(&server->srv_lock);
return 0;
}
if (nowait) {
spin_unlock(&server->srv_lock);
return -EAGAIN;
}
timeout *= server->nr_targets;
spin_unlock(&server->srv_lock);
@@ -1096,7 +1110,9 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry)
*/
do {
rc = wait_event_interruptible_timeout(server->response_q,
(server->tcpStatus != CifsNeedReconnect),
reco_wait_done(server,
tcon,
aborts),
timeout * HZ);
if (rc < 0) {
cifs_dbg(FYI, "%s: aborting reconnect due to received signal\n",
@@ -1111,7 +1127,7 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry)
return 0;
}
spin_unlock(&server->srv_lock);
} while (retry);
} while (cifs_tcon_retry(tcon, aborts));
cifs_dbg(FYI, "%s: gave up waiting on reconnect\n", __func__);
return -EHOSTDOWN;
+2 -2
View File
@@ -666,8 +666,8 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
}
if (memcmp(pblob->Signature, "NTLMSSP", 8)) {
cifs_dbg(VFS, "blob signature incorrect %s\n",
pblob->Signature);
cifs_dbg(VFS, "%s: blob signature incorrect: %8phN\n",
__func__, pblob->Signature);
return -EINVAL;
}
if (pblob->MessageType != NtLmChallenge) {
+13 -5
View File
@@ -175,6 +175,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
struct cifs_fid *fid = oparms->fid;
struct network_resiliency_req nr_ioctl_req;
bool retry_without_read_attributes = false;
bool reconnect = oparms->reconnect;
smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb);
if (smb2_path == NULL)
@@ -186,23 +187,30 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
* FILE_READ_ATTRIBUTES when not needed and prevent calling code path
* for retry_without_read_attributes.
*/
if (!(oparms->desired_access & FILE_READ_ATTRIBUTES) &&
!(oparms->desired_access & GENERIC_READ) &&
if (!(oparms->desired_access & GENERIC_READ) &&
!(oparms->desired_access & GENERIC_EXECUTE) &&
!(oparms->desired_access & GENERIC_ALL) &&
!(oparms->desired_access & MAXIMUM_ALLOWED)) {
oparms->desired_access |= FILE_READ_ATTRIBUTES;
retry_without_read_attributes = true;
if (oparms->replay) {
retry_without_read_attributes =
oparms->desired_access & FILE_READ_ATTRIBUTES;
} else if (!(oparms->desired_access & FILE_READ_ATTRIBUTES)) {
oparms->desired_access |= FILE_READ_ATTRIBUTES;
retry_without_read_attributes = true;
}
}
smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov,
&err_buftype);
if (rc == -EACCES && retry_without_read_attributes) {
if (rc == -EACCES && retry_without_read_attributes &&
!oparms->pending) {
free_rsp_buf(err_buftype, err_iov.iov_base);
memset(&err_iov, 0, sizeof(err_iov));
err_buftype = CIFS_NO_BUFFER;
oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
oparms->reconnect = reconnect;
oparms->replay = false;
rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov,
&err_buftype);
}
+12 -10
View File
@@ -244,7 +244,7 @@ smb2_get_credits(struct mid_q_entry *mid)
static int
smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
size_t *num, struct cifs_credits *credits)
size_t *num, struct cifs_credits *credits, bool nowait)
{
int rc = 0;
unsigned int scredits, in_flight;
@@ -258,6 +258,10 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
spin_unlock(&server->srv_lock);
return -ENOENT;
}
if (nowait && server->tcpStatus == CifsNeedReconnect) {
spin_unlock(&server->srv_lock);
return -EAGAIN;
}
spin_unlock(&server->srv_lock);
spin_lock(&server->req_lock);
@@ -265,7 +269,8 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
spin_unlock(&server->req_lock);
cifs_num_waiters_inc(server);
rc = wait_event_killable(server->request_q,
has_credits(server, &server->credits, 1));
credits_or_conn_down(server, &server->credits,
1, nowait));
cifs_num_waiters_dec(server);
if (rc)
return rc;
@@ -2933,15 +2938,12 @@ bool smb2_should_replay(struct cifs_tcon *tcon,
if (!pretries || !pcur_sleep)
return false;
/* the tcon is being torn down; stop replaying */
if (cifs_tcon_dying(tcon))
return false;
if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) {
/* Update sleep time for exponential backoff */
if (!(*pcur_sleep))
(*pcur_sleep) = 1;
else {
(*pcur_sleep) = ((*pcur_sleep) << 1);
if ((*pcur_sleep) > CIFS_MAX_SLEEP)
(*pcur_sleep) = CIFS_MAX_SLEEP;
}
smb2_replay_backoff(pcur_sleep);
return true;
}
+149 -59
View File
@@ -248,11 +248,14 @@ int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *serve
static int
smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
struct TCP_Server_Info *server, bool from_reconnect)
struct TCP_Server_Info *server, bool from_reconnect,
bool nowait)
{
bool hold_server_ref = false;
struct cifs_ses *ses;
int xid;
int rc = 0;
int aborts;
int xid;
/*
* SMB2s NegProt, SessSetup, Logoff do not have tcon yet so
@@ -262,6 +265,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
if (tcon == NULL)
return 0;
aborts = atomic_read(&tcon->umount_aborts);
if (smb2_command == SMB2_TREE_CONNECT)
return 0;
@@ -308,6 +313,10 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
spin_unlock(&server->srv_lock);
return -EAGAIN;
}
if (nowait) {
spin_unlock(&server->srv_lock);
return -EAGAIN;
}
}
/* if server is marked for termination, cifsd will cleanup */
@@ -318,7 +327,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
spin_unlock(&server->srv_lock);
again:
rc = cifs_wait_for_server_reconnect(server, tcon->retry);
rc = cifs_wait_for_server_reconnect(server, tcon, aborts, nowait);
if (rc)
return rc;
@@ -346,7 +355,9 @@ again:
case CifsNeedReconnect:
spin_unlock(&server->srv_lock);
mutex_unlock(&ses->session_mutex);
if (!tcon->retry)
if (nowait)
return -EAGAIN;
if (!cifs_tcon_retry(tcon, aborts))
return -EHOSTDOWN;
goto again;
default:
@@ -377,7 +388,9 @@ again:
rc = cifs_negotiate_protocol(0, ses, server);
if (rc) {
mutex_unlock(&ses->session_mutex);
if (!tcon->retry)
if (nowait)
return -EAGAIN;
if (!cifs_tcon_retry(tcon, aborts))
return -EHOSTDOWN;
goto again;
}
@@ -470,6 +483,20 @@ skip_sess_setup:
* treat this as server not supporting multichannel
*/
/*
* If server is a secondary channel,
* cifs_chan_skip_or_disable() called below may
* drop its last reference, so hold our own
* reference until the reconnect work below has
* been queued.
*/
spin_lock(&cifs_tcp_ses_lock);
if (server->srv_count) {
server->srv_count++;
hold_server_ref = true;
}
spin_unlock(&cifs_tcp_ses_lock);
rc = smb3_update_ses_channels(ses, server,
from_reconnect,
true /* disable_mchan */);
@@ -498,6 +525,8 @@ skip_add_channels:
if (smb2_command != SMB2_INTERNAL_CMD)
cifs_queue_server_reconn(server);
if (hold_server_ref)
cifs_put_tcp_session(server, from_reconnect);
atomic_inc(&tconInfoReconnectCount);
out:
@@ -589,7 +618,22 @@ static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon,
{
int rc;
rc = smb2_reconnect(smb2_command, tcon, server, false);
rc = smb2_reconnect(smb2_command, tcon, server, false, false);
if (rc)
return rc;
return __smb2_plain_req_init(smb2_command, tcon, server, request_buf,
total_len);
}
/* As smb2_plain_req_init(), but fail fast instead of waiting for reconnect. */
static int smb2_io_req_init(__le16 smb2_command, struct cifs_tcon *tcon,
struct TCP_Server_Info *server,
void **request_buf, unsigned int *total_len)
{
int rc;
rc = smb2_reconnect(smb2_command, tcon, server, false, true);
if (rc)
return rc;
@@ -3144,8 +3188,12 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
__le16 *copy_path;
int rc;
rc = smb2_plain_req_init(SMB2_CREATE, tcon, server,
(void **) &req, &total_len);
if (oparms->no_reconnect_wait)
rc = smb2_io_req_init(SMB2_CREATE, tcon, server,
(void **) &req, &total_len);
else
rc = smb2_plain_req_init(SMB2_CREATE, tcon, server,
(void **) &req, &total_len);
if (rc)
return rc;
@@ -3329,14 +3377,25 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
int flags = 0;
int retries = 0, cur_sleep = 0;
struct smb2_file_all_info *file_info = buf ? &buf->fi : NULL;
bool reconnect = oparms->reconnect;
bool replay = oparms->replay;
bool unanswered = replay;
bool answered;
bool sent;
replay_again:
/* reinitialize for possible replay */
answered = false;
sent = false;
resp_buftype = CIFS_NO_BUFFER;
memset(&rsp_iov, 0, sizeof(rsp_iov));
flags = 0;
server = cifs_pick_channel(ses);
oparms->replay = !!(retries);
/* reissue the same create: a durable reconnect clears ->reconnect */
oparms->reconnect = reconnect;
/* with no_replay the caller owns oparms->replay */
if (!oparms->no_replay)
oparms->replay = unanswered;
cifs_dbg(FYI, "create/open\n");
if (!ses || !server)
@@ -3344,6 +3403,8 @@ replay_again:
if (smb3_encryption_required(tcon))
flags |= CIFS_TRANSFORM_REQ;
if (oparms->no_reconnect_wait)
flags |= CIFS_NO_RECONNECT_WAIT;
memset(&rqst, 0, sizeof(struct smb_rqst));
memset(&iov, 0, sizeof(iov));
@@ -3354,21 +3415,22 @@ replay_again:
&rqst, oplock, oparms, path);
if (rc)
goto creat_exit;
sent = true;
trace_smb3_open_enter(xid, tcon->tid, tcon->ses->Suid, oparms->path,
oparms->create_options, oparms->desired_access);
if (retries) {
/* Back-off before retry */
if (cur_sleep)
msleep(cur_sleep);
/* Back-off before retry */
if (cur_sleep)
msleep(cur_sleep);
if (oparms->replay)
smb2_set_replay(server, &rqst);
}
rc = cifs_send_recv(xid, ses, server,
&rqst, &resp_buftype, flags,
&rsp_iov);
rsp = (struct smb2_create_rsp *)rsp_iov.iov_base;
answered = rsp;
if (rc != 0) {
cifs_stats_fail_inc(tcon, SMB2_CREATE_HE);
@@ -3425,10 +3487,27 @@ creat_exit:
SMB2_open_free(&rqst);
free_rsp_buf(resp_buftype, rsp);
if (is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep))
goto replay_again;
if (sent) {
if (!rc || (answered && (!oparms->replay ||
!is_replayable_error(rc))))
unanswered = false;
else if (!answered && !is_interrupt_error(rc))
unanswered = true;
oparms->pending = unanswered;
}
if (!oparms->no_replay && is_replayable_error(rc) &&
smb2_should_replay(tcon, &retries, &cur_sleep)) {
if (err_iov && answered && !rsp) {
free_rsp_buf(*buftype, err_iov->iov_base);
*err_iov = (struct kvec){};
*buftype = CIFS_NO_BUFFER;
}
goto replay_again;
}
if (!oparms->no_replay)
oparms->replay = replay;
return rc;
}
@@ -3439,11 +3518,12 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
char *in_data, u32 indatalen,
__u32 max_response_size)
{
struct smb2_ioctl_req *req;
struct kvec *iov = rqst->rq_iov;
struct smb2_ioctl_req *req;
u32 in_buf_len = indatalen;
unsigned int total_len;
int rc;
char *in_data_buf;
int rc;
rc = smb2_ioctl_req_init(opcode, tcon, server,
(void **) &req, &total_len);
@@ -3451,15 +3531,18 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
return rc;
if (indatalen) {
if (smb3_encryption_required(tcon))
in_buf_len = ALIGN(indatalen, 8);
/*
* indatalen is usually small at a couple of bytes max, so
* just allocate through generic pool
*/
in_data_buf = kmemdup(in_data, indatalen, GFP_NOFS);
in_data_buf = kzalloc(in_buf_len, GFP_NOFS);
if (!in_data_buf) {
cifs_small_buf_release(req);
return -ENOMEM;
}
memcpy(in_data_buf, in_data, indatalen);
}
req->CtlCode = cpu_to_le32(opcode);
@@ -3483,7 +3566,7 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
rqst->rq_nvec = 2;
iov[0].iov_len = total_len - 1;
iov[1].iov_base = in_data_buf;
iov[1].iov_len = indatalen;
iov[1].iov_len = in_buf_len;
} else {
rqst->rq_nvec = 1;
iov[0].iov_len = total_len;
@@ -4023,6 +4106,14 @@ replay_again:
ses->Suid, info_class, (__u32)info_type);
if (dlen) {
rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
le32_to_cpu(rsp->OutputBufferLength),
&rsp_iov, min_len);
if (rc) {
*dlen = 0;
goto qinf_exit;
}
*dlen = le32_to_cpu(rsp->OutputBufferLength);
if (!*data) {
*data = kmalloc(*dlen, GFP_KERNEL);
@@ -4077,7 +4168,8 @@ SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon,
return query_info(xid, tcon, persistent_fid, volatile_fid,
0, SMB2_O_INFO_SECURITY, extra_info,
SMB2_MAX_BUFFER_SIZE, MIN_SEC_DESC_LEN, data, plen);
SMB2_MAX_BUFFER_SIZE, sizeof(struct smb_ntsd),
data, plen);
}
int
@@ -4354,10 +4446,12 @@ void smb2_reconnect_server(struct work_struct *work)
spin_unlock(&cifs_tcp_ses_lock);
list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) {
rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true);
rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true,
true);
if (!rc) {
cifs_renegotiate_iosize(server, tcon);
cifs_reopen_persistent_handles(tcon);
if (cifs_reopen_persistent_handles(tcon))
resched = true;
} else
resched = true;
list_del_init(&tcon->rlist);
@@ -4386,7 +4480,8 @@ void smb2_reconnect_server(struct work_struct *work)
/* now reconnect sessions for necessary channels */
list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
tcon->ses = ses;
rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true);
rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true,
true);
if (rc)
resched = true;
list_del_init(&ses->rlist);
@@ -4695,6 +4790,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
struct smb_rqst rqst = { .rq_iov = &rdata->iov[0], .rq_nvec = 1 };
unsigned int rreq_debug_id = rdata->rreq->debug_id;
unsigned int subreq_debug_index = rdata->subreq.debug_index;
bool cut_short = false;
if (rdata->got_bytes) {
rqst.rq_iter = rdata->subreq.io_iter;
@@ -4743,6 +4839,7 @@ smb2_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
do_retry:
__set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
cut_short = true;
rdata->result = -EAGAIN;
if (server->sign && rdata->got_bytes)
/* reset bytes number since we can not check a sign */
@@ -4815,9 +4912,7 @@ do_retry:
/* see if we need to retry */
if (is_replayable_error(rdata->result) &&
smb2_should_replay(tcon,
&rdata->retries,
&rdata->cur_sleep))
(cut_short || cifs_io_should_replay(rdata)))
rdata->replay = true;
trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value,
@@ -4880,12 +4975,8 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
shdr = (struct smb2_hdr *)buf;
if (rdata->replay) {
/* Back-off before retry */
if (rdata->cur_sleep)
msleep(rdata->cur_sleep);
if (rdata->replay)
smb2_set_replay(server, &rqst);
}
if (rdata->credits.value > 0) {
shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(io_parms.length,
@@ -4926,9 +5017,7 @@ async_readv_out:
out:
/* if the send error is retryable, let netfs know about it */
if (is_replayable_error(rc) &&
smb2_should_replay(tcon,
&rdata->retries,
&rdata->cur_sleep)) {
cifs_io_should_replay(rdata)) {
rdata->replay = true;
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
@@ -5060,6 +5149,7 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
};
unsigned int rreq_debug_id = wdata->rreq->debug_id;
unsigned int subreq_debug_index = wdata->subreq.debug_index;
bool cut_short = false;
ssize_t result = 0;
size_t written = 0;
@@ -5073,10 +5163,7 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
credits.instance = server->reconnect_instance;
result = smb2_check_receive(mid, server, 0);
if (result != 0) {
if (is_replayable_error(result)) {
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
} else {
if (!is_replayable_error(result)) {
wdata->subreq.error = result;
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_bad);
}
@@ -5105,12 +5192,9 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
break;
case MID_REQUEST_SUBMITTED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_req_submitted);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
result = -EAGAIN;
break;
fallthrough;
case MID_RETRY_NEEDED:
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
cut_short = true;
result = -EAGAIN;
break;
case MID_RESPONSE_MALFORMED:
@@ -5164,11 +5248,17 @@ smb2_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
wdata->credits.value = 0;
/* see if we need to retry */
if (is_replayable_error(wdata->result) &&
smb2_should_replay(tcon,
&wdata->retries,
&wdata->cur_sleep))
if (is_replayable_error(result) &&
((cut_short && wdata->rreq->origin != NETFS_WRITEBACK &&
!cifs_io_stopped(wdata)) ||
cifs_io_should_replay(wdata))) {
wdata->replay = true;
trace_netfs_sreq(&wdata->subreq,
netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
} else if (cut_short && cifs_io_stopped(wdata)) {
result = -EIO;
}
cifs_write_subrequest_terminated(wdata, result ?: written);
release_mid(server, mid);
@@ -5209,8 +5299,14 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
};
io_parms = &_io_parms;
rc = smb2_plain_req_init(SMB2_WRITE, tcon, server,
(void **) &req, &total_len);
if (wdata->subreq.rreq->origin == NETFS_WRITEBACK) {
flags |= CIFS_NO_RECONNECT_WAIT;
rc = smb2_io_req_init(SMB2_WRITE, tcon, server,
(void **) &req, &total_len);
} else {
rc = smb2_plain_req_init(SMB2_WRITE, tcon, server,
(void **) &req, &total_len);
}
if (rc)
goto out;
@@ -5286,12 +5382,8 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
}
#endif
if (wdata->replay) {
/* Back-off before retry */
if (wdata->cur_sleep)
msleep(wdata->cur_sleep);
if (wdata->replay)
smb2_set_replay(server, &rqst);
}
cifs_dbg(FYI, "async write at %llu %u bytes iter=%zx\n",
io_parms->offset, io_parms->length, iov_iter_count(&wdata->subreq.io_iter));
@@ -5339,9 +5431,7 @@ async_writev_out:
out:
/* if the send error is retryable, let netfs know about it */
if (is_replayable_error(rc) &&
smb2_should_replay(tcon,
&wdata->retries,
&wdata->cur_sleep)) {
cifs_io_should_replay(wdata)) {
wdata->replay = true;
trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed);
__set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);
+9
View File
@@ -121,6 +121,15 @@ unsigned long smb_rqst_len(struct TCP_Server_Info *server,
void smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst);
void smb2_set_related(struct smb_rqst *rqst);
void smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst);
static inline void smb2_replay_backoff(int *pcur_sleep)
{
if (!*pcur_sleep)
*pcur_sleep = 1;
else
*pcur_sleep = min(*pcur_sleep << 1, CIFS_MAX_SLEEP);
}
bool smb2_should_replay(struct cifs_tcon *tcon, int *pretries,
int *pcur_sleep);
+18 -4
View File
@@ -430,6 +430,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
const int timeout, const int flags,
unsigned int *instance)
{
bool nowait = flags & CIFS_NO_RECONNECT_WAIT;
long rc;
int *credits;
int optype;
@@ -478,6 +479,10 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
spin_unlock(&server->srv_lock);
return -ENOENT;
}
if (nowait && server->tcpStatus == CifsNeedReconnect) {
spin_unlock(&server->srv_lock);
return -EAGAIN;
}
spin_unlock(&server->srv_lock);
spin_lock(&server->req_lock);
@@ -487,7 +492,8 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
cifs_num_waiters_inc(server);
rc = wait_event_killable_timeout(server->request_q,
has_credits(server, credits, num_credits), t);
credits_or_conn_down(server, credits,
num_credits, nowait), t);
cifs_num_waiters_dec(server);
if (!rc) {
spin_lock(&server->req_lock);
@@ -527,8 +533,9 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
cifs_num_waiters_inc(server);
rc = wait_event_killable_timeout(
server->request_q,
has_credits(server, credits,
MAX_COMPOUND + 1),
credits_or_conn_down(server, credits,
MAX_COMPOUND + 1,
nowait),
t);
cifs_num_waiters_dec(server);
if (!rc) {
@@ -595,6 +602,10 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num,
credits = server->ops->get_credits_field(server, flags & CIFS_OP_MASK);
if ((flags & CIFS_NO_RECONNECT_WAIT) &&
READ_ONCE(server->tcpStatus) == CifsNeedReconnect)
return -EAGAIN;
spin_lock(&server->req_lock);
scredits = *credits;
in_flight = server->in_flight;
@@ -618,6 +629,9 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num,
*/
if (server->in_flight == 0) {
spin_unlock(&server->req_lock);
if ((flags & CIFS_NO_RECONNECT_WAIT) &&
READ_ONCE(server->tcpStatus) == CifsNeedReconnect)
return -EAGAIN;
trace_smb3_insufficient_credits(server->current_mid,
server->conn_id, server->hostname, scredits,
num, in_flight);
@@ -634,7 +648,7 @@ wait_for_compound_request(struct TCP_Server_Info *server, int num,
int
cifs_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
size_t *num, struct cifs_credits *credits)
size_t *num, struct cifs_credits *credits, bool nowait)
{
*num = size;
credits->value = 0;