1/* 2 * Copyright (c) 2001-2007 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * The contents of this file constitute Original Code as defined in and 7 * are subject to the Apple Public Source License Version 1.1 (the 8 * "License"). You may not use this file except in compliance with the 9 * License. Please obtain a copy of the License at 10 * http://www.apple.com/publicsource and read it before using this file. 11 * 12 * This Original Code and all software distributed under the License are 13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 * License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22 23 24#ifndef _APPLERAIDSET_H 25#define _APPLERAIDSET_H 26 27#define kARSetCompleteTimeoutNone 0 28#define kARSetCompleteTimeoutDefault 30 29 30enum { 31 kAppleRAIDSetStateFailed = 0, 32 kAppleRAIDSetStateTerminating, 33 kAppleRAIDSetStateInitializing, 34 kAppleRAIDSetStateOnline, 35 kAppleRAIDSetStateDegraded 36}; 37 38class AppleRAIDSet : public AppleRAIDMember 39{ 40 OSDeclareAbstractStructors(AppleRAIDSet) 41 42 friend class AppleRAIDStorageRequest; 43 friend class AppleLVMStorageRequest; 44 friend class AppleRAID; 45 46protected: 47 UInt32 arSetState; 48 49 UInt32 arHeaderVersion; 50 UInt64 arSetBlockSize; 51 UInt64 arSetBlockCount; 52 UInt64 arSetMediaSize; 53 UInt32 arSequenceNumber; 54 55 UInt32 arSetCompleteTimeout; // for degradeable sets 56 57 IOStorageAccess arOpenLevel; 58 OSSet * arOpenReaders; 59 OSSet * arOpenReaderWriters; 60 61 IOMedia * arMedia; 62 63 UInt32 arSetIsPaused; 64 bool arSetWasBlockedByPause; 65 UInt32 arStorageRequestsPending; 66 UInt32 arMaxReadRequestFactor; 67 68 UInt64 arPrimaryMetaDataUsed; // mirror rebuild, lvg toc 69 UInt64 arPrimaryMetaDataMax; // mirror rebuild, lvg toc 70 71 thread_call_t arRecoveryThreadCall; 72 IOCommandGate::Action arAllocateRequestMethod; 73 74 UInt32 arActiveCount; 75 UInt32 arMemberCount; 76 UInt32 arLastAllocCount; 77 AppleRAIDMember **arMembers; 78 79 OSSet *arSpareMembers; 80 81 UInt32 *arLogicalMemberIndexes; 82 83 IOWorkLoop *arSetWorkLoop; 84 IOCommandGate *arSetCommandGate; 85 AppleRAIDEventSource *arSetEventSource; 86 87 IOCommandPool *arStorageRequestPool; 88 89 SInt32 arSetIsSyncingCount; 90 91 92 protected: 93 virtual void free(void); 94 virtual bool init(void); 95 virtual bool initWithHeader(OSDictionary * header, bool firstTime); 96 97 virtual bool handleOpen(IOService * client, IOOptionBits options, void * access); 98 virtual bool handleIsOpen(const IOService *client) const; 99 virtual void handleClose(IOService * client, IOOptionBits options); 100 101 virtual void recoverStart(void); 102 virtual void recoverWait(void); 103 virtual bool recover(void); 104 105 virtual bool pauseSet(bool whenIdle); 106 virtual void unpauseSet(void); 107 108 public: 109 110 virtual bool addSpare(AppleRAIDMember * member); 111 virtual bool addMember(AppleRAIDMember * member); 112 virtual bool removeMember(AppleRAIDMember * member, IOOptionBits options); 113 virtual bool upgradeMember(AppleRAIDMember *member); 114 115 virtual bool resizeSet(UInt32 newMemberCount); 116 virtual bool startSet(void); 117 virtual bool publishSet(void); 118 virtual bool unpublishSet(void); 119 virtual bool destroySet(void); 120 virtual bool reconfigureSet(OSDictionary * updateInfo); 121 122 virtual UInt32 getSequenceNumber(void); 123 virtual void bumpSequenceNumber(void); 124 virtual IOReturn writeRAIDHeader(void); 125 126 virtual IOBufferMemoryDescriptor * readPrimaryMetaData(AppleRAIDMember * member); 127 virtual IOReturn writePrimaryMetaData(IOBufferMemoryDescriptor * primaryBuffer); 128 virtual bool readIntoBuffer(AppleRAIDMember * member, IOBufferMemoryDescriptor * buffer, UInt64 offset); 129 virtual IOReturn writeFromBuffer(AppleRAIDMember * member, IOBufferMemoryDescriptor * buffer, UInt64 offset); 130 131 virtual const OSString * getSetName(void); 132 virtual const OSString * getUUID(void); 133 virtual const OSString * getSetUUID(void); 134 virtual const OSString * getDiskName(void); 135 136 virtual IOStorage * getTarget(void) const; 137 virtual bool isRAIDSet(void); 138 virtual bool isSetComplete(void); 139 virtual bool bumpOnError(void); 140 virtual UInt64 getSize(void) const; 141 virtual IOWorkLoop *getWorkLoop(void); 142 virtual bool changeSetState(UInt32 newState); 143 virtual UInt32 nextSetState(void); 144 virtual UInt64 getSmallestMaxByteCount(void); 145 virtual void setSmallest64BitMemberPropertyFor(const char * key, UInt32 multiplier); 146 virtual void setLargest64BitMemberPropertyFor(const char * key, UInt32 multiplier); 147 148 inline UInt32 getActiveCount(void) const { return arActiveCount; }; 149 inline UInt32 getMemberCount(void) const { return arMemberCount; }; 150 inline UInt32 getSpareCount(void) const { return arSpareMembers->getCount(); }; 151 inline UInt32 getSetState(void) const { return arSetState; }; 152 virtual UInt32 getMaxRequestCount(void) const { return arMemberCount; }; 153 154 virtual bool addBootDeviceInfo(OSArray * bootArray); 155 virtual OSDictionary * getSetProperties(void); 156 157 virtual void read(IOService * client, UInt64 byteStart, IOMemoryDescriptor* buffer, IOStorageAttributes * attributes, IOStorageCompletion * completion); 158 virtual void write(IOService * client, UInt64 byteStart, IOMemoryDescriptor* buffer, IOStorageAttributes * attributes, IOStorageCompletion * completion); 159 virtual void activeReadMembers(AppleRAIDMember ** activeMembers, UInt64 byteStart, UInt32 byteCount); 160 virtual void activeWriteMembers(AppleRAIDMember ** activeMembers, UInt64 byteStart, UInt32 byteCount); 161 162 virtual IOReturn synchronizeCache(IOService* client); 163 virtual IOReturn synchronizeCacheGated(IOService *client); 164 virtual void synchronizeStarted(void); 165 virtual void synchronizeCompleted(void); 166 virtual void synchronizeCompletedGated(void); 167 168 inline bool isPaused(void) const { return arSetIsPaused != 0; }; 169 170 virtual IOReturn allocateRAIDRequest(AppleRAIDStorageRequest **storageRequest); 171 virtual void returnRAIDRequest(AppleRAIDStorageRequest *storageRequest); 172 virtual void completeRAIDRequest(AppleRAIDStorageRequest *storageRequest); 173 174 virtual AppleRAIDMemoryDescriptor * allocateMemoryDescriptor(AppleRAIDStorageRequest *storageRequest, UInt32 memberIndex) = 0; 175}; 176 177#endif /* ! _APPLERAIDSET_H */ 178