struct page *alloc_page(int flags) { struct page *pg; pg = kmem_cache_alloc(cfs_page_t_slab, 0); if (NULL == pg) { cfs_enter_debugger(); return NULL; } memset(pg, 0, sizeof(struct page)); pg->addr = kmem_cache_alloc(cfs_page_p_slab, 0); cfs_atomic_set(&pg->count, 1); if (pg->addr) { if (cfs_is_flag_set(flags, __GFP_ZERO)) memset(pg->addr, 0, PAGE_CACHE_SIZE); cfs_atomic_inc(&libcfs_total_pages); } else { cfs_enter_debugger(); kmem_cache_free(cfs_page_t_slab, pg); pg = NULL; } return pg; }
struct page *virt_to_page(void *addr) { struct page *pg; pg = kmem_cache_alloc(cfs_page_t_slab, 0); if (NULL == pg) { cfs_enter_debugger(); return NULL; } memset(pg, 0, sizeof(struct page)); pg->addr = (void *)((__u64)addr & (~((__u64)PAGE_SIZE-1))); pg->mapping = addr; cfs_atomic_set(&pg->count, 1); set_bit(PG_virt, &(pg->flags)); cfs_enter_debugger(); return pg; }
PDEVICE_OBJECT LstCreateDevice( IN PDRIVER_OBJECT DriverObject, IN PWCHAR DeviceName, IN PWCHAR SymlnkName, IN BOOLEAN bProcFS ) { NTSTATUS Status; UNICODE_STRING NtDevName; UNICODE_STRING Win32DevName; PDEVICE_EXTENSION DeviceExtension; PDEVICE_OBJECT DeviceObject; /* create the device object with the specified name */ RtlInitUnicodeString(&NtDevName, DeviceName); Status = IoCreateDevice( DriverObject, sizeof(DEVICE_EXTENSION), &NtDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &DeviceObject ); if (!NT_SUCCESS(Status)) { cfs_enter_debugger(); return NULL; } /* create the symlink to make the device visible to user */ RtlInitUnicodeString(&Win32DevName, SymlnkName); Status = IoCreateSymbolicLink(&Win32DevName, &NtDevName); if (!NT_SUCCESS(Status)) { IoDeleteDevice(DeviceObject); return NULL; } DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceObjectExtension; DeviceExtension->bProcFS = bProcFS; DeviceObject->AlignmentRequirement = 0; DeviceObject->SectorSize = 0; DeviceObject->Flags |= DO_BUFFERED_IO; DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; return DeviceObject; }
NTSTATUS ProcReadWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp) { PIO_STACK_LOCATION IrpSp; NTSTATUS Status; struct file *fp; int rc; PCHAR buf; IrpSp = IoGetCurrentIrpStackLocation(Irp); if (Irp->MdlAddress) { buf = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority); } else { buf = Irp->AssociatedIrp.SystemBuffer; } if (buf == NULL) { Status = STATUS_SUCCESS; rc = 0; } else { fp = (struct file *)IrpSp->FileObject->FsContext; if (!fp) { Status = STATUS_INVALID_PARAMETER; goto errorout; } if (IrpSp->MajorFunction == IRP_MJ_READ) { rc = lustre_read_file( fp, IrpSp->Parameters.Read.ByteOffset.LowPart, IrpSp->Parameters.Read.Length, buf); } else { rc = lustre_write_file( fp, IrpSp->Parameters.Write.ByteOffset.LowPart, IrpSp->Parameters.Write.Length, buf); } if (rc < 0) { cfs_enter_debugger(); Status = STATUS_UNSUCCESSFUL; } else { Status = STATUS_SUCCESS; } } errorout: return LstCompleteIrp(Irp, Status, rc); }
/* * __free_page * To free the struct page including the page * * Arguments: * pg: pointer to the struct page strcture * * Return Value: * N/A * * Notes: * N/A */ void __free_page(struct page *pg) { ASSERT(pg != NULL); ASSERT(pg->addr != NULL); ASSERT(cfs_atomic_read(&pg->count) <= 1); if (!test_bit(PG_virt, &pg->flags)) { kmem_cache_free(cfs_page_p_slab, pg->addr); cfs_atomic_dec(&libcfs_total_pages); } else { cfs_enter_debugger(); } kmem_cache_free(cfs_page_t_slab, pg); }
void * kmalloc(size_t nr_bytes, u_int32_t flags) { void *ptr; /* Ignore the flags: always allcoate from NonPagedPool */ ptr = ExAllocatePoolWithTag(NonPagedPool, nr_bytes, 'Lufs'); if (ptr != NULL && (flags & __GFP_ZERO)) memset(ptr, 0, nr_bytes); if (!ptr) cfs_enter_debugger(); return ptr; }
struct trace_cpu_data *trace_get_tcd(void) { struct trace_cpu_data *tcd; int nr_pages; struct list_head pages; /* * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT) * from here: this will lead to infinite recursion. */ /* * debugging check for recursive call to libcfs_debug_msg() */ if (trace_owner == current_thread()) { /* * Cannot assert here. */ printk(KERN_EMERG "recursive call to %s", __FUNCTION__); /* * "The death of God left the angels in a strange position." */ cfs_enter_debugger(); } tcd = &trace_data[0].tcd; CFS_INIT_LIST_HEAD(&pages); if (get_preemption_level() == 0) nr_pages = trace_refill_stock(tcd, CFS_ALLOC_STD, &pages); else nr_pages = 0; spin_lock(&trace_cpu_serializer); trace_owner = current_thread(); tcd->tcd_cur_stock_pages += nr_pages; list_splice(&pages, &tcd->tcd_stock_pages); return tcd; }
NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { KdPrint(("LNet selftest: Build Time: " __DATE__ " " __TIME__ "\n")); KdPrint(("LNet selftest: DriverEntry ... \n")); /* initialize libcfs module */ if (module_init_libcfs_module() != 0) { KdPrint(("selftest: failed to initialize module: libcfs ...\n")); goto errorout; } /* initialize portals module */ if (module_init_lnet() != 0) { KdPrint(("selftest: failed to initialize module: lnet ...\n")); module_exit_libcfs_module(); goto errorout; } /* initialize tdinal module */ if (module_ksocknal_module_init() != 0) { KdPrint(("selftest: failed to initialize module: socklnd ...\n")); module_fini_lnet(); module_exit_libcfs_module(); goto errorout; } /* initialize lnet selttest module */ if (module_lnet_selftest_init() != 0) { KdPrint(("selftest: failed to initialize module: selftest ...\n")); module_ksocknal_module_fini(); module_fini_lnet(); module_exit_libcfs_module(); goto errorout; } /* create lnet selftest device object */ SelfObject = LstCreateDevice( DriverObject, LNET_SELFTEST_DEVICE, LNET_SELFTEST_SYMLNK, FALSE ); if (!SelfObject) { KdPrint(("selftest: failed to allocate DeviceObject ...\n")); module_lnet_selftest_fini(); module_ksocknal_module_fini(); module_fini_lnet(); module_exit_libcfs_module(); return STATUS_INSUFFICIENT_RESOURCES; } /* create the libcfs proc fs emultor device object */ ProcObject = LstCreateDevice( DriverObject, LUSTRE_PROC_DEVICE, LUSTRE_PROC_SYMLNK, TRUE ); if (!ProcObject) { KdPrint(("selftest: failed to allocate proc DeviceObject ...\n")); /* remove Selftest DeviceObject */ IoDeleteDevice(SelfObject); module_lnet_selftest_fini(); module_ksocknal_module_fini(); module_fini_lnet(); module_exit_libcfs_module(); return STATUS_INSUFFICIENT_RESOURCES; } /* initialize the driver callback routines */ DriverObject->MajorFunction[IRP_MJ_CREATE] = LstDispatchRequest; DriverObject->MajorFunction[IRP_MJ_CLOSE] = LstDispatchRequest; DriverObject->MajorFunction[IRP_MJ_READ] = LstDispatchRequest; DriverObject->MajorFunction[IRP_MJ_WRITE] = LstDispatchRequest; DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = LstDispatchRequest; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = LstDispatchRequest; return STATUS_SUCCESS; errorout: cfs_enter_debugger(); return STATUS_UNSUCCESSFUL; }