15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 22*5772Sas200622 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 265331Samw #pragma ident "%Z%%M% %I% %E% SMI" 275331Samw 285331Samw /* 295331Samw * The flush SMB is sent to ensure all data and allocation information 305331Samw * for the corresponding file has been written to stable storage. This 315331Samw * is a synchronous request. The response should not be sent until the 325331Samw * writes are complete. 335331Samw * 345331Samw * The SmbFlush request is described in CIFS/1.0 1996 Section 3.9.14. 355331Samw * 365331Samw * CIFS/1.0 June 13, 1996 375331Samw * Heizer, et al 385331Samw * draft-heizer-cifs-v1-spec-00.txt 395331Samw */ 405331Samw 415331Samw #include <smbsrv/smb_incl.h> 425331Samw #include <smbsrv/smb_fsops.h> 435331Samw 445331Samw 455331Samw static void smb_flush_file(struct smb_request *sr, struct smb_ofile *ofile); 465331Samw 475331Samw 485331Samw int smb_flush_required = 1; 495331Samw 505331Samw 515331Samw /* 525331Samw * smb_commit_required 535331Samw * 545331Samw * Specify whether or not SmbFlush should send commit requests to the 555331Samw * file system. If state is non-zero, commit requests will be sent to 565331Samw * the file system. If state is zero, SmbFlush is a no-op. 575331Samw */ 585331Samw void 595331Samw smb_commit_required(int state) 605331Samw { 615331Samw smb_flush_required = state; 625331Samw } 635331Samw 645331Samw 655331Samw /* 665331Samw * smb_com_flush 675331Samw * 685331Samw * Flush any cached data for a specified file, or for all files that 695331Samw * this client has open, to stable storage. If the fid is valid (i.e. 705331Samw * not 0xFFFF), we flush only that file. Otherwise we flush all files 715331Samw * associated with this client. 725331Samw * 735331Samw * We need to protect the list because there's a good chance we'll 745331Samw * block during the flush operation. 755331Samw */ 765331Samw int 775331Samw smb_com_flush(smb_request_t *sr) 785331Samw { 795331Samw smb_ofile_t *file; 805331Samw smb_llist_t *flist; 815331Samw 825331Samw if (smbsr_decode_vwv(sr, "w", &sr->smb_fid) != 0) { 835331Samw smbsr_decode_error(sr); 845331Samw /* NOTREACHED */ 855331Samw } 865331Samw 875331Samw if (smb_flush_required == 0) { 885331Samw smbsr_encode_empty_result(sr); 895331Samw return (SDRC_NORMAL_REPLY); 905331Samw } 915331Samw 925331Samw if (sr->smb_fid != 0xffff) { 935331Samw sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree, 945331Samw sr->smb_fid); 955331Samw if (sr->fid_ofile == NULL) { 96*5772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 975331Samw ERRDOS, ERRbadfid); 985331Samw /* NOTREACHED */ 995331Samw } 1005331Samw 1015331Samw smb_flush_file(sr, sr->fid_ofile); 1025331Samw } else { 1035331Samw flist = &sr->tid_tree->t_ofile_list; 1045331Samw smb_llist_enter(flist, RW_READER); 1055331Samw file = smb_llist_head(flist); 1065331Samw while (file) { 1075331Samw mutex_enter(&file->f_mutex); 1085331Samw smb_flush_file(sr, file); 1095331Samw mutex_exit(&file->f_mutex); 1105331Samw file = smb_llist_next(flist, file); 1115331Samw } 1125331Samw smb_llist_exit(flist); 1135331Samw } 1145331Samw smbsr_encode_empty_result(sr); 1155331Samw return (SDRC_NORMAL_REPLY); 1165331Samw } 1175331Samw 1185331Samw 1195331Samw /* 1205331Samw * smb_flush_file 1215331Samw * 1225331Samw * If writes on this file are not synchronous, flush it using the NFSv3 1235331Samw * commit interface. 1245331Samw */ 1255331Samw static void smb_flush_file(struct smb_request *sr, struct smb_ofile *ofile) 1265331Samw { 1275331Samw if ((ofile->f_node->flags & NODE_FLAGS_WRITE_THROUGH) == 0) 1285331Samw (void) smb_fsop_commit(sr, sr->user_cr, ofile->f_node); 1295331Samw } 130