Skip to content

Commit 8fe7062

Browse files
ematsumiyaSteve French
authored andcommitted
smb: client: negotiate compression algorithms
Change "compress=" mount option to a boolean flag, that, if set, will enable negotiating compression algorithms with the server. Do not de/compress anything for now. Signed-off-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 073dd87 commit 8fe7062

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

fs/smb/client/cifs_debug.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,24 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
278278
return 0;
279279
}
280280

281+
static __always_inline const char *compression_alg_str(__le16 alg)
282+
{
283+
switch (alg) {
284+
case SMB3_COMPRESS_NONE:
285+
return "NONE";
286+
case SMB3_COMPRESS_LZNT1:
287+
return "LZNT1";
288+
case SMB3_COMPRESS_LZ77:
289+
return "LZ77";
290+
case SMB3_COMPRESS_LZ77_HUFF:
291+
return "LZ77-Huffman";
292+
case SMB3_COMPRESS_PATTERN:
293+
return "Pattern_V1";
294+
default:
295+
return "invalid";
296+
}
297+
}
298+
281299
static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
282300
{
283301
struct mid_q_entry *mid_entry;
@@ -423,12 +441,6 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
423441
server->echo_credits,
424442
server->oplock_credits,
425443
server->dialect);
426-
if (server->compress_algorithm == SMB3_COMPRESS_LZNT1)
427-
seq_printf(m, " COMPRESS_LZNT1");
428-
else if (server->compress_algorithm == SMB3_COMPRESS_LZ77)
429-
seq_printf(m, " COMPRESS_LZ77");
430-
else if (server->compress_algorithm == SMB3_COMPRESS_LZ77_HUFF)
431-
seq_printf(m, " COMPRESS_LZ77_HUFF");
432444
if (server->sign)
433445
seq_printf(m, " signed");
434446
if (server->posix_ext_supported)
@@ -460,6 +472,14 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
460472
server->leaf_fullpath);
461473
}
462474

475+
seq_puts(m, "\nCompression: ");
476+
if (!server->compression.requested)
477+
seq_puts(m, "disabled on mount");
478+
else if (server->compression.enabled)
479+
seq_printf(m, "enabled (%s)", compression_alg_str(server->compression.alg));
480+
else
481+
seq_puts(m, "disabled (not supported by this server)");
482+
463483
seq_printf(m, "\n\n\tSessions: ");
464484
i = 0;
465485
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {

fs/smb/client/cifsglob.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,11 @@ struct TCP_Server_Info {
769769
unsigned int max_write;
770770
unsigned int min_offload;
771771
unsigned int retrans;
772-
__le16 compress_algorithm;
772+
struct {
773+
bool requested; /* "compress" mount option set*/
774+
bool enabled; /* actually negotiated with server */
775+
__le16 alg; /* preferred alg negotiated with server */
776+
} compression;
773777
__u16 signing_algorithm;
774778
__le16 cipher_type;
775779
/* save initital negprot hash */

fs/smb/client/connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
17361736
tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */
17371737
tcp_ses->reconnect_instance = 1;
17381738
tcp_ses->lstrp = jiffies;
1739-
tcp_ses->compress_algorithm = cpu_to_le16(ctx->compression);
1739+
tcp_ses->compression.requested = ctx->compress;
17401740
spin_lock_init(&tcp_ses->req_lock);
17411741
spin_lock_init(&tcp_ses->srv_lock);
17421742
spin_lock_init(&tcp_ses->mid_lock);

fs/smb/client/fs_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
963963

964964
switch (opt) {
965965
case Opt_compress:
966-
ctx->compression = UNKNOWN_TYPE;
966+
ctx->compress = true;
967967
cifs_dbg(VFS,
968968
"SMB3 compression support is experimental\n");
969969
break;

fs/smb/client/fs_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ struct smb3_fs_context {
273273
unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
274274
unsigned int max_channels;
275275
unsigned int max_cached_dirs;
276-
__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
276+
bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */
277277
bool rootfs:1; /* if it's a SMB root file system */
278278
bool witness:1; /* use witness protocol */
279279
char *leaf_fullpath;

fs/smb/client/smb2pdu.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
731731
pneg_ctxt += sizeof(struct smb2_posix_neg_context);
732732
neg_context_count++;
733733

734-
if (server->compress_algorithm) {
734+
if (server->compression.requested) {
735735
build_compression_ctxt((struct smb2_compression_capabilities_context *)
736736
pneg_ctxt);
737737
ctxt_len = ALIGN(sizeof(struct smb2_compression_capabilities_context), 8);
@@ -779,6 +779,9 @@ static void decode_compress_ctx(struct TCP_Server_Info *server,
779779
struct smb2_compression_capabilities_context *ctxt)
780780
{
781781
unsigned int len = le16_to_cpu(ctxt->DataLength);
782+
__le16 alg;
783+
784+
server->compression.enabled = false;
782785

783786
/*
784787
* Caller checked that DataLength remains within SMB boundary. We still
@@ -789,15 +792,22 @@ static void decode_compress_ctx(struct TCP_Server_Info *server,
789792
pr_warn_once("server sent bad compression cntxt\n");
790793
return;
791794
}
795+
792796
if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) {
793-
pr_warn_once("Invalid SMB3 compress algorithm count\n");
797+
pr_warn_once("invalid SMB3 compress algorithm count\n");
794798
return;
795799
}
796-
if (le16_to_cpu(ctxt->CompressionAlgorithms[0]) > 3) {
797-
pr_warn_once("unknown compression algorithm\n");
800+
801+
alg = ctxt->CompressionAlgorithms[0];
802+
803+
/* 'NONE' (0) compressor type is never negotiated */
804+
if (alg == 0 || le16_to_cpu(alg) > 3) {
805+
pr_warn_once("invalid compression algorithm '%u'\n", alg);
798806
return;
799807
}
800-
server->compress_algorithm = ctxt->CompressionAlgorithms[0];
808+
809+
server->compression.alg = alg;
810+
server->compression.enabled = true;
801811
}
802812

803813
static int decode_encrypt_ctx(struct TCP_Server_Info *server,

0 commit comments

Comments
 (0)