aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSteve French <smfrench@gmail.com>2013-10-14 16:27:32 -0400
committerSteve French <smfrench@gmail.com>2013-11-02 13:52:44 -0400
commitc7f508a99bf229963915e79a603e0618d1d2ba76 (patch)
treeb2eaa3a16ccafe2aa1d28130edaa552dd900f66c /fs
parentaf6a12ea8d4bb39a87527835b943bde4215897e5 (diff)
Allow setting per-file compression via CIFS protocol
An earlier patch allowed setting the per-file compression flag "chattr +c filename" on an smb2 or smb3 mount, and also allowed lsattr to return whether a file on a cifs, or smb2/smb3 mount was compressed. This patch extends the ability to set the per-file compression flag to the cifs protocol, which uses a somewhat different IOCTL mechanism than SMB2, although the payload (the flags stored in the compression_state) are the same. Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/cifspdu.h29
-rw-r--r--fs/cifs/cifsproto.h2
-rw-r--r--fs/cifs/cifssmb.c54
-rw-r--r--fs/cifs/smb1ops.c8
-rw-r--r--fs/cifs/smb2pdu.h5
5 files changed, 94 insertions, 4 deletions
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index f80f98f5ef9c..9e5ee34de986 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -1352,6 +1352,35 @@ typedef struct smb_com_transaction_ioctl_req {
1352 __u8 Data[1]; 1352 __u8 Data[1];
1353} __attribute__((packed)) TRANSACT_IOCTL_REQ; 1353} __attribute__((packed)) TRANSACT_IOCTL_REQ;
1354 1354
1355typedef struct smb_com_transaction_compr_ioctl_req {
1356 struct smb_hdr hdr; /* wct = 23 */
1357 __u8 MaxSetupCount;
1358 __u16 Reserved;
1359 __le32 TotalParameterCount;
1360 __le32 TotalDataCount;
1361 __le32 MaxParameterCount;
1362 __le32 MaxDataCount;
1363 __le32 ParameterCount;
1364 __le32 ParameterOffset;
1365 __le32 DataCount;
1366 __le32 DataOffset;
1367 __u8 SetupCount; /* four setup words follow subcommand */
1368 /* SNIA spec incorrectly included spurious pad here */
1369 __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1370 __le32 FunctionCode;
1371 __u16 Fid;
1372 __u8 IsFsctl; /* 1 = File System Control 0 = device control (IOCTL) */
1373 __u8 IsRootFlag; /* 1 = apply command to root of share (must be DFS) */
1374 __le16 ByteCount;
1375 __u8 Pad[3];
1376 __le16 compression_state; /* See below for valid flags */
1377} __attribute__((packed)) TRANSACT_COMPR_IOCTL_REQ;
1378
1379/* compression state flags */
1380#define COMPRESSION_FORMAT_NONE 0x0000
1381#define COMPRESSION_FORMAT_DEFAULT 0x0001
1382#define COMPRESSION_FORMAT_LZNT1 0x0002
1383
1355typedef struct smb_com_transaction_ioctl_rsp { 1384typedef struct smb_com_transaction_ioctl_rsp {
1356 struct smb_hdr hdr; /* wct = 19 */ 1385 struct smb_hdr hdr; /* wct = 19 */
1357 __u8 Reserved[3]; 1386 __u8 Reserved[3];
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index b5ec2a268f56..aa3397620342 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -360,6 +360,8 @@ extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,
360extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, 360extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
361 __u16 fid, char **symlinkinfo, 361 __u16 fid, char **symlinkinfo,
362 const struct nls_table *nls_codepage); 362 const struct nls_table *nls_codepage);
363extern int CIFSSMB_set_compression(const unsigned int xid,
364 struct cifs_tcon *tcon, __u16 fid);
363extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, 365extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
364 const char *fileName, const int disposition, 366 const char *fileName, const int disposition,
365 const int access_flags, const int omode, 367 const int access_flags, const int omode,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index ccd31ab815d4..93b29474714a 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -3199,6 +3199,60 @@ qreparse_out:
3199 return rc; 3199 return rc;
3200} 3200}
3201 3201
3202int
3203CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
3204 __u16 fid)
3205{
3206 int rc = 0;
3207 int bytes_returned;
3208 struct smb_com_transaction_compr_ioctl_req *pSMB;
3209 struct smb_com_transaction_ioctl_rsp *pSMBr;
3210
3211 cifs_dbg(FYI, "Set compression for %u\n", fid);
3212 rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
3213 (void **) &pSMBr);
3214 if (rc)
3215 return rc;
3216
3217 pSMB->compression_state = cpu_to_le16(COMPRESSION_FORMAT_DEFAULT);
3218
3219 pSMB->TotalParameterCount = 0;
3220 pSMB->TotalDataCount = __constant_cpu_to_le32(2);
3221 pSMB->MaxParameterCount = 0;
3222 pSMB->MaxDataCount = 0;
3223 pSMB->MaxSetupCount = 4;
3224 pSMB->Reserved = 0;
3225 pSMB->ParameterOffset = 0;
3226 pSMB->DataCount = __constant_cpu_to_le32(2);
3227 pSMB->DataOffset =
3228 cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req,
3229 compression_state) - 4); /* 84 */
3230 pSMB->SetupCount = 4;
3231 pSMB->SubCommand = __constant_cpu_to_le16(NT_TRANSACT_IOCTL);
3232 pSMB->ParameterCount = 0;
3233 pSMB->FunctionCode = __constant_cpu_to_le32(FSCTL_SET_COMPRESSION);
3234 pSMB->IsFsctl = 1; /* FSCTL */
3235 pSMB->IsRootFlag = 0;
3236 pSMB->Fid = fid; /* file handle always le */
3237 /* 3 byte pad, followed by 2 byte compress state */
3238 pSMB->ByteCount = __constant_cpu_to_le16(5);
3239 inc_rfc1001_len(pSMB, 5);
3240
3241 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
3242 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
3243 if (rc)
3244 cifs_dbg(FYI, "Send error in SetCompression = %d\n", rc);
3245
3246 cifs_buf_release(pSMB);
3247
3248 /*
3249 * Note: On -EAGAIN error only caller can retry on handle based calls
3250 * since file handle passed in no longer valid.
3251 */
3252 return rc;
3253}
3254
3255
3202#ifdef CONFIG_CIFS_POSIX 3256#ifdef CONFIG_CIFS_POSIX
3203 3257
3204/*Convert an Access Control Entry from wire format to local POSIX xattr format*/ 3258/*Convert an Access Control Entry from wire format to local POSIX xattr format*/
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index 09ef8f322c2a..384cffe42850 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -807,6 +807,13 @@ out:
807} 807}
808 808
809static int 809static int
810cifs_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
811 struct cifsFileInfo *cfile)
812{
813 return CIFSSMB_set_compression(xid, tcon, cfile->fid.netfid);
814}
815
816static int
810cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, 817cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
811 const char *path, struct cifs_sb_info *cifs_sb, 818 const char *path, struct cifs_sb_info *cifs_sb,
812 struct cifs_fid *fid, __u16 search_flags, 819 struct cifs_fid *fid, __u16 search_flags,
@@ -956,6 +963,7 @@ struct smb_version_operations smb1_operations = {
956 .set_path_size = CIFSSMBSetEOF, 963 .set_path_size = CIFSSMBSetEOF,
957 .set_file_size = CIFSSMBSetFileSize, 964 .set_file_size = CIFSSMBSetFileSize,
958 .set_file_info = smb_set_file_info, 965 .set_file_info = smb_set_file_info,
966 .set_compression = cifs_set_compression,
959 .echo = CIFSSMBEcho, 967 .echo = CIFSSMBEcho,
960 .mkdir = CIFSSMBMkDir, 968 .mkdir = CIFSSMBMkDir,
961 .mkdir_setinfo = cifs_mkdir_setinfo, 969 .mkdir_setinfo = cifs_mkdir_setinfo,
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index 7e44f18cc169..6183b1b7550f 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -570,12 +570,9 @@ struct network_interface_info_ioctl_rsp {
570#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */ 570#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
571 571
572struct compress_ioctl { 572struct compress_ioctl {
573 __le16 CompressionState; 573 __le16 CompressionState; /* See cifspdu.h for possible flag values */
574} __packed; 574} __packed;
575 575
576#define COMPRESSION_FORMAT_NONE 0x0000
577#define COMPRESSION_FORMAT_DEFAULT 0x0001
578#define COMPRESSION_FORMAT_LZNT1 0x0002
579struct smb2_ioctl_req { 576struct smb2_ioctl_req {
580 struct smb2_hdr hdr; 577 struct smb2_hdr hdr;
581 __le16 StructureSize; /* Must be 57 */ 578 __le16 StructureSize; /* Must be 57 */