compress.h (d14bbfff259cadb5af84413658699159556da156) | compress.h (94ae8c3fee94a87bdf982d5559f8037c6c562657) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (C) 2024, SUSE LLC 4 * 5 * Authors: Enzo Matsumiya <ematsumiya@suse.de> 6 * 7 * This file implements I/O compression support for SMB2 messages (SMB 3.1.1 only). 8 * See compress/ for implementation details of each algorithm. --- 12 unchanged lines hidden (view full) --- 21#include "cifsglob.h" 22 23/* sizeof(smb2_compression_hdr) - sizeof(OriginalPayloadSize) */ 24#define SMB_COMPRESS_HDR_LEN 16 25/* sizeof(smb2_compression_payload_hdr) - sizeof(OriginalPayloadSize) */ 26#define SMB_COMPRESS_PAYLOAD_HDR_LEN 8 27#define SMB_COMPRESS_MIN_LEN PAGE_SIZE 28 | 1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (C) 2024, SUSE LLC 4 * 5 * Authors: Enzo Matsumiya <ematsumiya@suse.de> 6 * 7 * This file implements I/O compression support for SMB2 messages (SMB 3.1.1 only). 8 * See compress/ for implementation details of each algorithm. --- 12 unchanged lines hidden (view full) --- 21#include "cifsglob.h" 22 23/* sizeof(smb2_compression_hdr) - sizeof(OriginalPayloadSize) */ 24#define SMB_COMPRESS_HDR_LEN 16 25/* sizeof(smb2_compression_payload_hdr) - sizeof(OriginalPayloadSize) */ 26#define SMB_COMPRESS_PAYLOAD_HDR_LEN 8 27#define SMB_COMPRESS_MIN_LEN PAGE_SIZE 28 |
29struct smb_compress_ctx { 30 struct TCP_Server_Info *server; 31 struct work_struct work; 32 struct mid_q_entry *mid; | 29#ifdef CONFIG_CIFS_COMPRESSION 30typedef int (*compress_send_fn)(struct TCP_Server_Info *, int, struct smb_rqst *); |
33 | 31 |
34 void *buf; /* compressed data */ 35 void *data; /* uncompressed data */ 36 size_t len; 37}; | 32int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_send_fn send_fn); |
38 | 33 |
39#ifdef CONFIG_CIFS_COMPRESSION 40int smb_compress(void *buf, const void *data, size_t *len); | 34/** 35 * should_compress() - Determines if a request (write) or the response to a 36 * request (read) should be compressed. 37 * @tcon: tcon of the request is being sent to 38 * @rqst: request to evaluate 39 * 40 * Return: true iff: 41 * - compression was successfully negotiated with server 42 * - server has enabled compression for the share 43 * - it's a read or write request 44 * - (write only) request length is >= SMB_COMPRESS_MIN_LEN 45 * - (write only) is_compressible() returns 1 46 * 47 * Return false otherwise. 48 */ 49bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq); |
41 42/** 43 * smb_compress_alg_valid() - Validate a compression algorithm. 44 * @alg: Compression algorithm to check. 45 * @valid_none: Conditional check whether NONE algorithm should be 46 * considered valid or not. 47 * 48 * If @alg is SMB3_COMPRESS_NONE, this function returns @valid_none. --- 8 unchanged lines hidden (view full) --- 57 if (alg == SMB3_COMPRESS_NONE) 58 return valid_none; 59 60 if (alg == SMB3_COMPRESS_LZ77 || alg == SMB3_COMPRESS_PATTERN) 61 return true; 62 63 return false; 64} | 50 51/** 52 * smb_compress_alg_valid() - Validate a compression algorithm. 53 * @alg: Compression algorithm to check. 54 * @valid_none: Conditional check whether NONE algorithm should be 55 * considered valid or not. 56 * 57 * If @alg is SMB3_COMPRESS_NONE, this function returns @valid_none. --- 8 unchanged lines hidden (view full) --- 66 if (alg == SMB3_COMPRESS_NONE) 67 return valid_none; 68 69 if (alg == SMB3_COMPRESS_LZ77 || alg == SMB3_COMPRESS_PATTERN) 70 return true; 71 72 return false; 73} |
74#else /* !CONFIG_CIFS_COMPRESSION */ 75static inline int smb_compress(void *unused1, void *unused2, void *unused3) 76{ 77 return -EOPNOTSUPP; 78} |
|
65 | 79 |
66/** 67 * should_compress() - Determines if a request (write) or the response to a 68 * request (read) should be compressed. 69 * @tcon: tcon of the request is being sent to 70 * @buf: buffer with an SMB2 READ/WRITE request 71 * 72 * Return: true iff: 73 * - compression was successfully negotiated with server 74 * - server has enabled compression for the share 75 * - it's a read or write request 76 * - if write, request length is >= SMB_COMPRESS_MIN_LEN 77 * 78 * Return false otherwise. 79 */ 80static __always_inline bool should_compress(const struct cifs_tcon *tcon, const void *buf) | 80static inline bool should_compress(void *unused1, void *unused2) |
81{ | 81{ |
82 const struct smb2_hdr *shdr = buf; | 82 return false; 83} |
83 | 84 |
84 if (!tcon || !tcon->ses || !tcon->ses->server) 85 return false; 86 87 if (!tcon->ses->server->compression.enabled) 88 return false; 89 90 if (!(tcon->share_flags & SMB2_SHAREFLAG_COMPRESS_DATA)) 91 return false; 92 93 if (shdr->Command == SMB2_WRITE) { 94 const struct smb2_write_req *req = buf; 95 96 return (req->Length >= SMB_COMPRESS_MIN_LEN); 97 } 98 99 return (shdr->Command == SMB2_READ); | 85static inline int smb_compress_alg_valid(__le16 unused1, bool unused2) 86{ 87 return -EOPNOTSUPP; |
100} | 88} |
101/* 102 * #else !CONFIG_CIFS_COMPRESSION ... 103 * These routines should not be called when CONFIG_CIFS_COMPRESSION disabled 104 * #define smb_compress(arg1, arg2, arg3) (-EOPNOTSUPP) 105 * #define smb_compress_alg_valid(arg1, arg2) (-EOPNOTSUPP) 106 * #define should_compress(arg1, arg2) (false) 107 */ | |
108#endif /* !CONFIG_CIFS_COMPRESSION */ 109#endif /* _SMB_COMPRESS_H */ | 89#endif /* !CONFIG_CIFS_COMPRESSION */ 90#endif /* _SMB_COMPRESS_H */ |