Author: axeld Date: 2010-06-01 14:05:24 +0200 (Tue, 01 Jun 2010) New Revision: 36986 Changeset: http://dev.haiku-os.org/changeset/36986/haiku Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp haiku/trunk/src/system/kernel/device_manager/IOCache.cpp haiku/trunk/src/system/kernel/device_manager/IOCache.h haiku/trunk/src/system/kernel/device_manager/IOScheduler.cpp haiku/trunk/src/system/kernel/device_manager/IOScheduler.h Log: * Introduced IOScheduler::MediaChanged() - this is now called by scsi_cd instead of having the logic be triggered by IOScheduler::SetDeviceCapacity(), as that one might actually be called more often (for each call to update_capacity(), ie. each B_GET_GEOMETRY/B_GET_DEVICE_SIZE will trigger it), and there is no reason to throw away the cache every time (will make a difference during partition/file system detection). * In cd_init_device() just call update_capacity() instead of duplicating its code. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp 2010-06-01 11:59:23 UTC (rev 36985) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/scsi/scsi_cd/scsi_cd.cpp 2010-06-01 12:05:24 UTC (rev 36986) @@ -1,10 +1,11 @@ /* - * Copyright 2004-2009, Haiku, Inc. All rights reserved. + * Copyright 2004-2010, Haiku, Inc. All rights reserved. * Copyright 2002-2003, Thomas Kurschel. All rights reserved. * * Distributed under the terms of the MIT License. */ + /*! Peripheral driver to handle CD-ROM drives. To be more precisely, it supports CD-ROM and WORM drives (well - I've never _seen_ a WORM driver). @@ -586,13 +587,10 @@ cd_driver_info* info = (cd_driver_info*)_info; // and get (initial) capacity - scsi_ccb *request = info->scsi->alloc_ccb(info->scsi_device); - if (request == NULL) - return B_NO_MEMORY; + status_t status = update_capacity(info); + if (status != B_OK) + return status; - sSCSIPeripheral->check_capacity(info->scsi_periph_device, request); - info->scsi->free_ccb(request); - *_cookie = info; return B_OK; } @@ -929,6 +927,9 @@ // do a capacity check // TBD: is this a good idea (e.g. if this is an empty CD)? sSCSIPeripheral->check_capacity(info->scsi_periph_device, request); + + if (info->io_scheduler != NULL) + info->io_scheduler->MediaChanged(); } Modified: haiku/trunk/src/system/kernel/device_manager/IOCache.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/IOCache.cpp 2010-06-01 11:59:23 UTC (rev 36985) +++ haiku/trunk/src/system/kernel/device_manager/IOCache.cpp 2010-06-01 12:05:24 UTC (rev 36986) @@ -133,7 +133,17 @@ AutoLocker<VMCache> cacheLocker(fCache); fDeviceCapacity = deviceCapacity; +} + +void +IOCache::MediaChanged() +{ + TRACE("%p->IOCache::MediaChanged()\n", this); + + MutexLocker serializationLocker(fSerializationLock); + AutoLocker<VMCache> cacheLocker(fCache); + // new media -- burn all cached data while (vm_page* page = fCache->pages.Root()) { DEBUG_PAGE_ACCESS_START(page); Modified: haiku/trunk/src/system/kernel/device_manager/IOCache.h =================================================================== --- haiku/trunk/src/system/kernel/device_manager/IOCache.h 2010-06-01 11:59:23 UTC (rev 36985) +++ haiku/trunk/src/system/kernel/device_manager/IOCache.h 2010-06-01 12:05:24 UTC (rev 36986) @@ -26,6 +26,7 @@ virtual status_t Init(const char* name); virtual void SetDeviceCapacity(off_t deviceCapacity); + virtual void MediaChanged(); virtual status_t ScheduleRequest(IORequest* request); Modified: haiku/trunk/src/system/kernel/device_manager/IOScheduler.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/IOScheduler.cpp 2010-06-01 11:59:23 UTC (rev 36985) +++ haiku/trunk/src/system/kernel/device_manager/IOScheduler.cpp 2010-06-01 12:05:24 UTC (rev 36986) @@ -66,3 +66,9 @@ IOScheduler::SetDeviceCapacity(off_t deviceCapacity) { } + + +void +IOScheduler::MediaChanged() +{ +} Modified: haiku/trunk/src/system/kernel/device_manager/IOScheduler.h =================================================================== --- haiku/trunk/src/system/kernel/device_manager/IOScheduler.h 2010-06-01 11:59:23 UTC (rev 36985) +++ haiku/trunk/src/system/kernel/device_manager/IOScheduler.h 2010-06-01 12:05:24 UTC (rev 36986) @@ -46,6 +46,7 @@ virtual void SetCallback(io_callback callback, void* data); virtual void SetDeviceCapacity(off_t deviceCapacity); + virtual void MediaChanged(); virtual status_t ScheduleRequest(IORequest* request) = 0;