Skip to content

Commit 9fe5ff1

Browse files
committed
smb3: do not send compression info by default
Since in theory a server could respond with compressed read responses even if not requested on read request (assuming that a compression negcontext is sent in negotiate protocol) - do not send compression information during negotiate protocol unless the user asks for compression explicitly (compression is experimental), and add a mount warning that compression is experimental. Signed-off-by: Steve French <[email protected]> Reviewed-by: Ronnie Sahlberg <[email protected]>
1 parent 412094a commit 9fe5ff1

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

fs/cifs/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ struct smb_vol {
601601
__u64 snapshot_time; /* needed for timewarp tokens */
602602
__u32 handle_timeout; /* persistent and durable handle timeout in ms */
603603
unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
604+
__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
604605
};
605606

606607
/**

fs/cifs/connect.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ enum {
9797
Opt_persistent, Opt_nopersistent,
9898
Opt_resilient, Opt_noresilient,
9999
Opt_domainauto, Opt_rdma, Opt_modesid,
100+
Opt_compress,
100101

101102
/* Mount options which take numeric value */
102103
Opt_backupuid, Opt_backupgid, Opt_uid,
@@ -213,6 +214,7 @@ static const match_table_t cifs_mount_option_tokens = {
213214
{ Opt_echo_interval, "echo_interval=%s" },
214215
{ Opt_max_credits, "max_credits=%s" },
215216
{ Opt_snapshot, "snapshot=%s" },
217+
{ Opt_compress, "compress=%s" },
216218

217219
{ Opt_blank_user, "user=" },
218220
{ Opt_blank_user, "username=" },
@@ -1915,6 +1917,11 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
19151917
case Opt_rdma:
19161918
vol->rdma = true;
19171919
break;
1920+
case Opt_compress:
1921+
vol->compression = UNKNOWN_TYPE;
1922+
cifs_dbg(VFS,
1923+
"SMB3 compression support is experimental\n");
1924+
break;
19181925

19191926
/* Numeric Values */
19201927
case Opt_backupuid:
@@ -2691,6 +2698,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
26912698
tcp_ses->sequence_number = 0;
26922699
tcp_ses->reconnect_instance = 1;
26932700
tcp_ses->lstrp = jiffies;
2701+
tcp_ses->compress_algorithm = cpu_to_le16(volume_info->compression);
26942702
spin_lock_init(&tcp_ses->req_lock);
26952703
INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
26962704
INIT_LIST_HEAD(&tcp_ses->smb_ses_list);

fs/cifs/smb2pdu.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
521521

522522
static void
523523
assemble_neg_contexts(struct smb2_negotiate_req *req,
524-
unsigned int *total_len)
524+
struct TCP_Server_Info *server, unsigned int *total_len)
525525
{
526526
char *pneg_ctxt = (char *)req;
527527
unsigned int ctxt_len;
@@ -551,17 +551,19 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
551551
*total_len += ctxt_len;
552552
pneg_ctxt += ctxt_len;
553553

554-
build_compression_ctxt((struct smb2_compression_capabilities_context *)
554+
if (server->compress_algorithm) {
555+
build_compression_ctxt((struct smb2_compression_capabilities_context *)
555556
pneg_ctxt);
556-
ctxt_len = DIV_ROUND_UP(
557-
sizeof(struct smb2_compression_capabilities_context), 8) * 8;
558-
*total_len += ctxt_len;
559-
pneg_ctxt += ctxt_len;
560-
557+
ctxt_len = DIV_ROUND_UP(
558+
sizeof(struct smb2_compression_capabilities_context),
559+
8) * 8;
560+
*total_len += ctxt_len;
561+
pneg_ctxt += ctxt_len;
562+
req->NegotiateContextCount = cpu_to_le16(4);
563+
} else
564+
req->NegotiateContextCount = cpu_to_le16(3);
561565
build_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt);
562566
*total_len += sizeof(struct smb2_posix_neg_context);
563-
564-
req->NegotiateContextCount = cpu_to_le16(4);
565567
}
566568

567569
static void decode_preauth_context(struct smb2_preauth_neg_context *ctxt)
@@ -829,7 +831,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
829831
if ((ses->server->vals->protocol_id == SMB311_PROT_ID) ||
830832
(strcmp(ses->server->vals->version_string,
831833
SMBDEFAULT_VERSION_STRING) == 0))
832-
assemble_neg_contexts(req, &total_len);
834+
assemble_neg_contexts(req, server, &total_len);
833835
}
834836
iov[0].iov_base = (char *)req;
835837
iov[0].iov_len = total_len;

0 commit comments

Comments
 (0)