1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * Copyright 2016 Syneto S.R.L. All rights reserved. 26 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 27 * Copyright 2022 RackTop Systems, Inc. 28 */ 29 30 /* 31 * The flush SMB is sent to ensure all data and allocation information 32 * for the corresponding file has been written to stable storage. This 33 * is a synchronous request. The response should not be sent until the 34 * writes are complete. 35 * 36 * The SmbFlush request is described in CIFS/1.0 1996 Section 3.9.14. 37 * 38 * CIFS/1.0 June 13, 1996 39 * Heizer, et al 40 * draft-heizer-cifs-v1-spec-00.txt 41 */ 42 43 #include <smbsrv/smb_kproto.h> 44 #include <smbsrv/smb_fsops.h> 45 46 47 /* 48 * smb_com_flush 49 * 50 * Flush any cached data for a specified file, or for all files that 51 * this client has open, to stable storage. If the fid is valid (i.e. 52 * not 0xFFFF), we flush only that file. Otherwise we flush all files 53 * associated with this client. 54 * 55 * We need to protect the list because there's a good chance we'll 56 * block during the flush operation. 57 */ 58 smb_sdrc_t 59 smb_pre_flush(smb_request_t *sr) 60 { 61 int rc; 62 63 rc = smbsr_decode_vwv(sr, "w", &sr->smb_fid); 64 65 DTRACE_SMB_START(op__Flush, smb_request_t *, sr); 66 67 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 68 } 69 70 void 71 smb_post_flush(smb_request_t *sr) 72 { 73 DTRACE_SMB_DONE(op__Flush, smb_request_t *, sr); 74 } 75 76 smb_sdrc_t 77 smb_com_flush(smb_request_t *sr) 78 { 79 smb_ofile_t *file; 80 smb_lavl_t *lavl; 81 int rc; 82 83 if (smb_flush_required == 0) { 84 rc = smbsr_encode_empty_result(sr); 85 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 86 } 87 88 if (sr->smb_fid != 0xffff) { 89 smbsr_lookup_file(sr); 90 if (sr->fid_ofile == NULL) { 91 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 92 ERRDOS, ERRbadfid); 93 return (SDRC_ERROR); 94 } 95 smb_ofile_flush(sr, sr->fid_ofile); 96 } else { 97 lavl = &sr->tid_tree->t_ofile_list; 98 smb_lavl_enter(lavl, RW_READER); 99 file = smb_lavl_first(lavl); 100 while (file) { 101 mutex_enter(&file->f_mutex); 102 smb_ofile_flush(sr, file); 103 mutex_exit(&file->f_mutex); 104 file = smb_lavl_next(lavl, file); 105 } 106 smb_lavl_exit(lavl); 107 } 108 109 rc = smbsr_encode_empty_result(sr); 110 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 111 } 112