1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Matt Wu <mattwu@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_LNET
30 #include <libcfs/libcfs.h>
33 /* libcfs module init/exit routines */
34 DECLARE_INIT(init_libcfs_module);
35 DECLARE_EXIT(exit_libcfs_module);
37 /* portal module init/exit routines */
38 DECLARE_INIT(init_lnet);
39 DECLARE_EXIT(fini_lnet);
41 /* tdinal module init/exit routines */
42 DECLARE_INIT(ksocknal_module_init);
43 DECLARE_EXIT(ksocknal_module_fini);
45 /* pingcli module init/exit routines */
46 DECLARE_INIT(pingcli_init);
47 DECLARE_EXIT(pingcli_cleanup);
50 /* pingsrv module init/exit routines */
51 DECLARE_INIT(pingsrv_init);
52 DECLARE_EXIT(pingsrv_cleanup);
55 * structure definitions
59 #define LUSTRE_PING_VERSION 0x00010000 /* ping srv/cli version: 0001.0000 */
61 #define LUSTRE_PING_DEVICE L"\\Device\\LNET" /* device object name */
62 #define LUSTRE_PING_SYMLNK L"\\DosDevices\\LNET" /* user-visible name for the device*/
64 typedef struct _DEVICE_EXTENSION
68 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
75 PDEVICE_OBJECT PingObject = NULL; /* ping device object */
76 PDEVICE_OBJECT ProcObject = NULL; /* procfs emulator device */
85 // complete Irp request ...
95 Irp->IoStatus.Status = Status;
96 Irp->IoStatus.Information = Info;
97 IoCompleteRequest(Irp,IO_NO_INCREMENT);
103 // Open/Create Device ...
108 IN PDEVICE_OBJECT DeviceObject,
112 KdPrint(("UTCreate: DeviceCreate ...\n"));
114 return UTCompleteIrp(Irp,STATUS_SUCCESS,0);
123 IN PDEVICE_OBJECT DeviceObject,
126 KdPrint(("UTClose: Device Closed.\n"));
128 return UTCompleteIrp(Irp, STATUS_SUCCESS, 0);
130 UNREFERENCED_PARAMETER(DeviceObject);
137 IN PDEVICE_OBJECT DeviceObject,
141 KdPrint(("UTShutdown: shuting TdiSock ...\n"));
143 return UTCompleteIrp(Irp, STATUS_SUCCESS, 0);
145 UNREFERENCED_PARAMETER(DeviceObject);
149 // driver frame Routines ...
155 IN PDEVICE_OBJECT DeviceObject,
159 NTSTATUS Status = STATUS_INVALID_DEVICE_REQUEST;
160 PIO_STACK_LOCATION IrpSp;
168 KdPrint(("UTDeviceControl: Device Ioctl ...\n"));
170 Irp->IoStatus.Information = 0;
171 IrpSp = IoGetCurrentIrpStackLocation(Irp);
173 ControlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
174 InputLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
175 OutputLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
176 lpvInBuffer = Irp->AssociatedIrp.SystemBuffer;
178 ASSERT (IrpSp->MajorFunction == IRP_MJ_DEVICE_CONTROL);
182 case IOCTL_LIBCFS_VERSION:
184 *((ULONG *)lpvInBuffer) = (ULONG)(LUSTRE_PING_VERSION);
185 Irp->IoStatus.Information = sizeof(ULONG);
186 Status = STATUS_SUCCESS;
193 Irp->IoStatus.Status = Status;
195 IoCompleteRequest(Irp, IO_NO_INCREMENT);
197 KdPrint(("UTDeviceControl: Device Ioctl returned.\n"));
204 IN PDEVICE_OBJECT DeviceObject,
209 PIO_STACK_LOCATION IrpSp;
211 FILE_FULL_EA_INFORMATION * ea;
214 KdPrint(("ProcCreate: Proc device is being opened ...\n"));
216 IrpSp = IoGetCurrentIrpStackLocation(Irp);
217 ea = (PFILE_FULL_EA_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
220 Status = STATUS_INVALID_PARAMETER;
222 fp = lustre_open_file(&ea->EaName[0]);
224 Status = STATUS_OBJECT_NAME_NOT_FOUND;
226 IrpSp->FileObject->FsContext = fp;
227 IrpSp->FileObject->FsContext2 = fp->private_data;
228 Status = STATUS_SUCCESS;
232 return UTCompleteIrp(Irp, Status, 0);
241 IN PDEVICE_OBJECT DeviceObject,
244 PIO_STACK_LOCATION IrpSp;
248 KdPrint(("ProcClose: Proc device object is to be closed.\n"));
250 IrpSp = IoGetCurrentIrpStackLocation(Irp);
252 fp = (cfs_file_t *) IrpSp->FileObject->FsContext;
255 ASSERT(IrpSp->FileObject->FsContext2 == fp->private_data);
257 lustre_close_file(fp);
259 return UTCompleteIrp(Irp, STATUS_SUCCESS, 0);
261 UNREFERENCED_PARAMETER(DeviceObject);
265 * proc frame routines
270 IN PDEVICE_OBJECT DeviceObject,
274 NTSTATUS Status = STATUS_INVALID_DEVICE_REQUEST;
275 PIO_STACK_LOCATION IrpSp;
283 KdPrint(("ProcDeviceControl: Proc device ioctling ...\n"));
285 Irp->IoStatus.Information = 0;
286 IrpSp = IoGetCurrentIrpStackLocation(Irp);
288 ControlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
289 InputLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
290 OutputLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
291 lpvInBuffer = Irp->AssociatedIrp.SystemBuffer;
293 ASSERT (IrpSp->MajorFunction == IRP_MJ_DEVICE_CONTROL);
297 case IOCTL_LIBCFS_VERSION:
299 *((ULONG *)lpvInBuffer) = (ULONG)(LUSTRE_PING_VERSION);
300 Irp->IoStatus.Information = sizeof(ULONG);
302 Status = STATUS_SUCCESS;
306 case IOCTL_LIBCFS_ENTRY:
311 fp = (cfs_file_t *) IrpSp->FileObject->FsContext;
316 rc = lustre_ioctl_file(fp, (PCFS_PROC_IOCTL) (lpvInBuffer));
320 Irp->IoStatus.Information = InputLength;
321 Status = STATUS_SUCCESS;
326 Irp->IoStatus.Status = Status;
328 IoCompleteRequest(Irp, IO_NO_INCREMENT);
330 KdPrint(("ProcDeviceControl: Proc device ioctl returned with status = %xh.\n", Status));
338 ProcReadWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
340 PIO_STACK_LOCATION IrpSp;
347 IrpSp = IoGetCurrentIrpStackLocation(Irp);
348 if (Irp->MdlAddress) {
349 buf = MmGetSystemAddressForMdlSafe(
353 buf = Irp->AssociatedIrp.SystemBuffer;
357 Status = STATUS_SUCCESS;
360 fp = (cfs_file_t *) IrpSp->FileObject->FsContext;
363 Status = STATUS_INVALID_PARAMETER;
367 if (IrpSp->MajorFunction == IRP_MJ_READ) {
368 rc = lustre_read_file(
369 fp, IrpSp->Parameters.Read.ByteOffset.LowPart,
370 IrpSp->Parameters.Read.Length, buf);
372 rc = lustre_write_file(
373 fp, IrpSp->Parameters.Write.ByteOffset.LowPart,
374 IrpSp->Parameters.Write.Length, buf);
377 cfs_enter_debugger();
378 Status = STATUS_UNSUCCESSFUL;
380 Status = STATUS_SUCCESS;
386 return UTCompleteIrp(Irp, Status, rc);
391 // common dispatch routines
396 IN PDEVICE_OBJECT DeviceObject,
401 PIO_STACK_LOCATION IrpSp;
403 Status = STATUS_INVALID_DEVICE_REQUEST;
407 IrpSp = IoGetCurrentIrpStackLocation(Irp);
409 switch (IrpSp->MajorFunction) {
412 if (DeviceObject == PingObject) {
413 Status = UTCreate(DeviceObject, Irp);
414 } else if (DeviceObject == ProcObject) {
415 Status = ProcCreate(DeviceObject, Irp);
420 if (DeviceObject == PingObject) {
421 Status = UTClose(DeviceObject, Irp);
422 } else if (DeviceObject == ProcObject) {
423 Status = ProcClose(DeviceObject, Irp);
429 if (DeviceObject == ProcObject) {
430 Status = ProcReadWrite(DeviceObject, Irp);
434 case IRP_MJ_DEVICE_CONTROL:
435 if (DeviceObject == PingObject) {
436 Status = UTDeviceControl(DeviceObject, Irp);
437 } else if (DeviceObject == ProcObject) {
438 Status = ProcDeviceControl(DeviceObject, Irp);
442 case IRP_MJ_SHUTDOWN:
443 Status = UTShutdown(DeviceObject, Irp);
448 KdPrint(("UTDispatchRequest: Major Function: %xh is not supported.\n",
449 IrpSp->MajorFunction));
450 UTCompleteIrp(Irp, Status, 0);
462 // create a device object and a dosdevice symbol link
467 IN PDRIVER_OBJECT DriverObject,
468 IN PWCHAR DeviceName,
469 IN PWCHAR SymlnkName,
475 UNICODE_STRING NtDevName;
476 UNICODE_STRING Win32DevName;
478 PDEVICE_EXTENSION DeviceExtension;
479 PDEVICE_OBJECT DeviceObject;
481 /* create the device object with the specified name */
483 RtlInitUnicodeString(&NtDevName, DeviceName);
485 Status = IoCreateDevice(
487 sizeof(DEVICE_EXTENSION),
494 if (!NT_SUCCESS(Status)) {
496 cfs_enter_debugger();
500 /* create the symlink to make the device visible to user */
502 RtlInitUnicodeString(&Win32DevName, SymlnkName);
504 Status = IoCreateSymbolicLink(&Win32DevName, &NtDevName);
506 if (!NT_SUCCESS(Status)) {
508 IoDeleteDevice(DeviceObject);
512 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceObjectExtension;
513 DeviceExtension->bProcFS = bProcFS;
515 DeviceObject->Flags |= DO_BUFFERED_IO;
516 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
526 NTSTATUS DriverEntry(
527 IN PDRIVER_OBJECT DriverObject,
528 IN PUNICODE_STRING RegistryPath
531 KdPrint(("Lustre ping test: Build Time: " __DATE__ " " __TIME__ "\n"));
532 KdPrint(("Lustre ping test: DriverEntry ... \n"));
534 /* initialize libcfs module */
535 if (module_init_libcfs_module() != 0) {
536 KdPrint(("ping: error initialize module: libcfs ...\n"));
540 /* initialize lnet module */
541 if (module_init_lnet() != 0) {
542 module_exit_libcfs_module();
543 KdPrint(("ping: error initialize module: lnet ...\n"));
547 /* initialize tdinal module */
548 if (module_ksocknal_module_init() != 0) {
550 module_exit_libcfs_module();
551 KdPrint(("ping: error initialize module: tdilnd ...\n"));
555 #if defined(LUSTRE_PING_CLI)
556 /* initialize pingcli module */
557 if (module_pingcli_init() != 0) {
558 module_ksocknal_module_fini();
560 module_exit_libcfs_module();
561 KdPrint(("ping: error initialize module: pingcli ...\n"));
566 #if defined(LUSTRE_PING_SRV)
567 /* initialize pingsrv module */
568 if (module_pingsrv_init() != 0) {
569 module_ksocknal_module_fini();
571 module_exit_libcfs_module();
572 KdPrint(("ping: error initialize module: pingsrv ...\n"));
577 /* create the ping device object */
578 PingObject = CreateDevice(
584 #if defined(LUSTRE_PING_CLI)
585 module_pingcli_cleanup();
587 #if defined(LUSTRE_PING_SRV)
588 module_pingsrv_cleanup();
590 module_ksocknal_module_fini();
592 module_exit_libcfs_module();
594 return STATUS_INSUFFICIENT_RESOURCES;
597 /* create the libcfs proc fs emultor device object */
598 ProcObject = CreateDevice(
605 IoDeleteDevice(PingObject);
606 #if defined(LUSTRE_PING_CLI)
607 module_pingcli_cleanup();
609 #if defined(LUSTRE_PING_SRV)
610 module_pingsrv_cleanup();
612 module_ksocknal_module_fini();
614 module_exit_libcfs_module();
615 return STATUS_INSUFFICIENT_RESOURCES;
618 /* initialize the driver callback routines */
620 DriverObject->MajorFunction[IRP_MJ_CREATE] = UTDispatchRequest;
621 DriverObject->MajorFunction[IRP_MJ_CLOSE] = UTDispatchRequest;
622 DriverObject->MajorFunction[IRP_MJ_READ] = UTDispatchRequest;
623 DriverObject->MajorFunction[IRP_MJ_WRITE] = UTDispatchRequest;
624 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = UTDispatchRequest;
625 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = UTDispatchRequest;
627 return STATUS_SUCCESS;
631 cfs_enter_debugger();
633 return STATUS_UNSUCCESSFUL;