Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_init.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_init.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/conf.h>
28 28 #include <sys/ddi.h>
29 29 #include <sys/modctl.h>
30 30 #include <sys/cred.h>
31 31 #include <sys/disp.h>
32 32 #include <sys/ioccom.h>
33 33 #include <sys/policy.h>
34 34 #include <sys/cmn_err.h>
35 35 #include <smbsrv/smb_kproto.h>
36 36 #include <smbsrv/smb_ioctl.h>
37 37
38 38 #ifdef _FAKE_KERNEL
39 39 #error "See libfksmbsrv"
40 40 #endif /* _FAKE_KERNEL */
41 41
42 42 static int smb_drv_open(dev_t *, int, int, cred_t *);
43 43 static int smb_drv_close(dev_t, int, int, cred_t *);
44 44 static int smb_drv_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
45 45 static int smb_drv_attach(dev_info_t *, ddi_attach_cmd_t);
46 46 static int smb_drv_detach(dev_info_t *, ddi_detach_cmd_t);
47 47 static int smb_drv_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
48 48
49 49 /*
50 50 * *****************************************************************************
51 51 * ****************************** Global Variables *****************************
52 52 * *****************************************************************************
53 53 *
54 54 * These variables can only be changed through the /etc/system file.
55 55 */
56 56
57 57 /*
58 58 * Maximum buffer size for NT: configurable based on the client environment.
59 59 * IR104720 Experiments with Windows 2000 indicate that we achieve better
60 60 * SmbWriteX performance with a buffer size of 64KB instead of the 37KB used
61 61 * with Windows NT4.0. Previous experiments with NT4.0 resulted in directory
62 62 * listing problems so this buffer size is configurable based on the end-user
63 63 * environment. When in doubt use 37KB.
64 64 */
65 65 int smb_maxbufsize = SMB_NT_MAXBUF;
66 66 int smb_oplock_levelII = 1;
67 67 int smb_oplock_timeout = OPLOCK_STD_TIMEOUT;
68 68 int smb_oplock_min_timeout = OPLOCK_MIN_TIMEOUT;
69 69 int smb_flush_required = 1;
70 70 int smb_dirsymlink_enable = 1;
71 71 int smb_sign_debug = 0;
72 72 int smb_shortnames = 1;
73 73 uint_t smb_audit_flags =
74 74 #ifdef DEBUG
75 75 SMB_AUDIT_NODE;
76 76 #else
77 77 0;
78 78 #endif
79 79
80 80 /*
81 81 * Maximum number of simultaneous authentication, share mapping, pipe open
82 82 * requests to be processed.
83 83 */
84 84 int smb_ssetup_threshold = SMB_AUTHSVC_MAXTHREAD;
85 85 int smb_tcon_threshold = 1024;
86 86 int smb_opipe_threshold = 1024;
87 87
88 88 /*
89 89 * Number of milliseconds that a request will be stalled if it comes in after
90 90 * the maximum number of inflight operations are being proccessed.
91 91 */
92 92 int smb_ssetup_timeout = (30 * 1000);
93 93 int smb_tcon_timeout = (30 * 1000);
94 94 int smb_opipe_timeout = (30 * 1000);
95 95
96 96 /*
97 97 * Thread priorities used in smbsrv. Our threads spend most of their time
98 98 * blocked on various conditions. However, if the system gets heavy load,
99 99 * the scheduler has to choose an order to run these. We want the order:
100 100 * (a) timers, (b) notifications, (c) workers, (d) receivers (and etc.)
101 101 * where notifications are oplock and change notify work. Aside from this
102 102 * relative ordering, smbsrv threads should run with a priority close to
103 103 * that of normal user-space threads (thus minclsyspri below), just like
104 104 * NFS and other "file service" kinds of processing.
105 105 */
106 106 int smbsrv_base_pri = MINCLSYSPRI;
107 107 int smbsrv_listen_pri = MINCLSYSPRI;
108 108 int smbsrv_receive_pri = MINCLSYSPRI;
109 109 int smbsrv_worker_pri = MINCLSYSPRI + 1;
110 110 int smbsrv_notify_pri = MINCLSYSPRI + 2;
111 111 int smbsrv_timer_pri = MINCLSYSPRI + 5;
112 112
113 113
114 114 /*
115 115 * *****************************************************************************
116 116 * ********************** Static Variables / Module Linkage ********************
117 117 * *****************************************************************************
118 118 */
119 119
120 120 static struct cb_ops cbops = {
121 121 smb_drv_open, /* cb_open */
122 122 smb_drv_close, /* cb_close */
123 123 nodev, /* cb_strategy */
124 124 nodev, /* cb_print */
125 125 nodev, /* cb_dump */
126 126 nodev, /* cb_read */
127 127 nodev, /* cb_write */
128 128 smb_drv_ioctl, /* cb_ioctl */
129 129 nodev, /* cb_devmap */
130 130 nodev, /* cb_mmap */
131 131 nodev, /* cb_segmap */
132 132 nochpoll, /* cb_chpoll */
133 133 ddi_prop_op, /* cb_prop_op */
134 134 NULL, /* cb_streamtab */
135 135 D_MP, /* cb_flag */
136 136 CB_REV, /* cb_rev */
137 137 nodev, /* cb_aread */
138 138 nodev, /* cb_awrite */
139 139 };
140 140
141 141 static struct dev_ops devops = {
142 142 DEVO_REV, /* devo_rev */
143 143 0, /* devo_refcnt */
144 144 smb_drv_getinfo, /* devo_getinfo */
145 145 nulldev, /* devo_identify */
146 146 nulldev, /* devo_probe */
147 147 smb_drv_attach, /* devo_attach */
148 148 smb_drv_detach, /* devo_detach */
149 149 nodev, /* devo_reset */
150 150 &cbops, /* devo_cb_ops */
151 151 NULL, /* devo_bus_ops */
152 152 NULL, /* devo_power */
153 153 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
154 154 };
155 155
156 156 static struct modldrv modldrv = {
157 157 &mod_driverops, /* drv_modops */
158 158 "CIFS Server Protocol", /* drv_linkinfo */
159 159 &devops,
160 160 };
161 161
162 162 static struct modlinkage modlinkage = {
163 163 MODREV_1, /* revision of the module, must be: MODREV_1 */
164 - &modldrv, /* ptr to linkage structures */
165 - NULL,
164 + { &modldrv, NULL } /* ptr to linkage structures */
166 165 };
167 166
168 167 static dev_info_t *smb_drv_dip = NULL;
169 168
170 169 /*
171 170 * ****************************************************************************
172 171 * Module Interface
173 172 * ****************************************************************************
174 173 */
175 174
176 175 int
177 176 _init(void)
178 177 {
179 178 int rc;
180 179
181 180 if ((rc = smb_server_g_init()) != 0) {
182 181 return (rc);
183 182 }
184 183
185 184 if ((rc = mod_install(&modlinkage)) != 0) {
186 185 smb_server_g_fini();
187 186 }
188 187
189 188 return (rc);
190 189 }
191 190
192 191 int
193 192 _info(struct modinfo *modinfop)
194 193 {
195 194 return (mod_info(&modlinkage, modinfop));
196 195 }
197 196
198 197 int
199 198 _fini(void)
200 199 {
201 200 int rc;
202 201
203 202 if (smb_server_get_count() != 0)
204 203 return (EBUSY);
205 204
206 205 if ((rc = mod_remove(&modlinkage)) == 0) {
207 206 smb_server_g_fini();
208 207 }
209 208
210 209 return (rc);
211 210 }
212 211
213 212 /*
214 213 * ****************************************************************************
215 214 * Pseudo Device Entry Points
216 215 * ****************************************************************************
217 216 */
218 217 /* ARGSUSED */
219 218 static int
220 219 smb_drv_open(dev_t *devp, int flag, int otyp, cred_t *cr)
221 220 {
222 221 zoneid_t zid;
223 222
224 223 /*
225 224 * Check caller's privileges.
226 225 */
227 226 if (secpolicy_smb(cr) != 0)
228 227 return (EPERM);
229 228
230 229 /*
231 230 * We need a unique minor per zone otherwise an smbd in any other
232 231 * zone will keep this minor open and we won't get a close call.
233 232 * The zone ID is good enough as a minor number.
234 233 */
235 234 zid = crgetzoneid(cr);
236 235 if (zid < 0)
237 236 return (ENODEV);
238 237 *devp = makedevice(getmajor(*devp), zid);
239 238
240 239 /*
241 240 * Start SMB service state machine
242 241 */
243 242 return (smb_server_create());
244 243 }
245 244
246 245 /* ARGSUSED */
247 246 static int
248 247 smb_drv_close(dev_t dev, int flag, int otyp, cred_t *credp)
249 248 {
250 249 return (smb_server_delete());
251 250 }
252 251
253 252 /* ARGSUSED */
254 253 static int
255 254 smb_drv_ioctl(dev_t drv, int cmd, intptr_t argp, int flags, cred_t *cred,
256 255 int *retval)
257 256 {
258 257 smb_ioc_t *ioc;
259 258 smb_ioc_header_t ioc_hdr;
260 259 uint32_t crc;
261 260 boolean_t copyout = B_FALSE;
262 261 int rc = 0;
263 262
264 263 if (ddi_copyin((const void *)argp, &ioc_hdr, sizeof (smb_ioc_header_t),
265 264 flags) || (ioc_hdr.version != SMB_IOC_VERSION))
266 265 return (EFAULT);
267 266
268 267 crc = ioc_hdr.crc;
269 268 ioc_hdr.crc = 0;
270 269 if (smb_crc_gen((uint8_t *)&ioc_hdr, sizeof (ioc_hdr)) != crc)
271 270 return (EFAULT);
272 271
273 272 ioc = kmem_alloc(ioc_hdr.len, KM_SLEEP);
274 273 if (ddi_copyin((const void *)argp, ioc, ioc_hdr.len, flags)) {
275 274 kmem_free(ioc, ioc_hdr.len);
276 275 return (EFAULT);
277 276 }
278 277
279 278 switch (cmd) {
280 279 case SMB_IOC_CONFIG:
281 280 rc = smb_server_configure(&ioc->ioc_cfg);
282 281 break;
283 282 case SMB_IOC_START:
284 283 rc = smb_server_start(&ioc->ioc_start);
285 284 break;
286 285 case SMB_IOC_STOP:
287 286 rc = smb_server_stop();
288 287 break;
289 288 case SMB_IOC_EVENT:
290 289 rc = smb_server_notify_event(&ioc->ioc_event);
291 290 break;
292 291 case SMB_IOC_GMTOFF:
293 292 rc = smb_server_set_gmtoff(&ioc->ioc_gmt);
294 293 break;
295 294 case SMB_IOC_SHARE:
296 295 rc = smb_kshare_export_list(&ioc->ioc_share);
297 296 break;
298 297 case SMB_IOC_UNSHARE:
299 298 rc = smb_kshare_unexport_list(&ioc->ioc_share);
300 299 break;
301 300 case SMB_IOC_SHAREINFO:
302 301 rc = smb_kshare_info(&ioc->ioc_shareinfo);
303 302 copyout = B_TRUE;
304 303 break;
305 304 case SMB_IOC_NUMOPEN:
306 305 rc = smb_server_numopen(&ioc->ioc_opennum);
307 306 copyout = B_TRUE;
308 307 break;
309 308 case SMB_IOC_SVCENUM:
310 309 rc = smb_server_enum(&ioc->ioc_svcenum);
311 310 copyout = B_TRUE;
312 311 break;
313 312 case SMB_IOC_SESSION_CLOSE:
314 313 rc = smb_server_session_close(&ioc->ioc_session);
315 314 break;
316 315 case SMB_IOC_FILE_CLOSE:
317 316 rc = smb_server_file_close(&ioc->ioc_fileid);
318 317 break;
319 318 case SMB_IOC_SPOOLDOC:
320 319 rc = smb_server_spooldoc(&ioc->ioc_spooldoc);
321 320 copyout = B_TRUE;
322 321 break;
323 322 default:
324 323 rc = ENOTTY;
325 324 break;
326 325 }
327 326 if ((rc == 0) && copyout) {
328 327 if (ddi_copyout((const void *)ioc, (void *)argp, ioc_hdr.len,
329 328 flags))
330 329 rc = EFAULT;
331 330 }
332 331 kmem_free(ioc, ioc_hdr.len);
333 332 return (rc);
334 333 }
335 334
336 335 /*
337 336 * ****************************************************************************
338 337 * Pseudo Device Operations
339 338 * ****************************************************************************
340 339 */
341 340 static int
342 341 smb_drv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
343 342 {
344 343 if (cmd == DDI_ATTACH) {
345 344 /* we only allow instance 0 to attach */
346 345 if (ddi_get_instance(dip) == 0) {
347 346 /* create the minor node */
348 347 if (ddi_create_minor_node(dip, "smbsrv", S_IFCHR, 0,
349 348 DDI_PSEUDO, 0) == DDI_SUCCESS) {
350 349 smb_drv_dip = dip;
351 350 return (DDI_SUCCESS);
352 351 } else {
353 352 cmn_err(CE_WARN, "smb_drv_attach:"
354 353 " failed creating minor node");
355 354 }
356 355 }
357 356 }
358 357 return (DDI_FAILURE);
359 358 }
360 359
361 360 static int
362 361 smb_drv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
363 362 {
364 363 if (cmd == DDI_DETACH) {
365 364 ASSERT(dip == smb_drv_dip);
366 365 ddi_remove_minor_node(dip, NULL);
367 366 smb_drv_dip = NULL;
368 367 return (DDI_SUCCESS);
369 368 }
370 369 return (DDI_FAILURE);
371 370 }
372 371
373 372 /* ARGSUSED */
374 373 static int
375 374 smb_drv_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
376 375 {
377 376 ulong_t instance = getminor((dev_t)arg);
378 377
379 378 switch (cmd) {
380 379 case DDI_INFO_DEVT2DEVINFO:
381 380 *result = smb_drv_dip;
382 381 return (DDI_SUCCESS);
383 382
384 383 case DDI_INFO_DEVT2INSTANCE:
385 384 *result = (void *)instance;
386 385 return (DDI_SUCCESS);
387 386
388 387 default:
389 388 break;
390 389 }
391 390
392 391 return (DDI_FAILURE);
393 392 }
↓ open down ↓ |
218 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX