Skip to content

Commit

Permalink
Diskless: Fixing unnecessarily needed storagepools
Browse files Browse the repository at this point in the history
If a DRBD or a Writecache layer is configure above an nvme,
the target resource will not create the LV for external metadata or
writecache. However, until now, the target node also had to have
the storagepool definied in the corresponding property
("StorPoolNameDrbdMeta" / "Writecache/PoolName"). Otherwise
the controller reported an error which would have led to a
nullpointer.
  • Loading branch information
ghernadi committed Dec 16, 2019
1 parent 6a4d9a0 commit ddc51b7
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ protected boolean needsChildVlm(AbsRscLayerObject<Resource> childRscDataRef, Vol
return needsChild;
}

private boolean isDrbdDiskless(AbsRscLayerObject<Resource> childRscDataRef) throws AccessDeniedException
{
return childRscDataRef.getAbsResource().getStateFlags()
.isSet(apiCtx, Resource.Flags.DRBD_DISKLESS);
}

@Override
protected DrbdVlmData<Resource> createVlmLayerData(
DrbdRscData<Resource> drbdRscData,
Expand All @@ -282,7 +288,11 @@ protected DrbdVlmData<Resource> createVlmLayerData(
drbdRscData.getResourceNameSuffix(),
payload
);
StorPool extMetaStorPool = getExternalMetaDiskStorPool(vlm);
StorPool extMetaStorPool = null;
if (needsMetaData(drbdRscData, layerListRef))
{
extMetaStorPool = getExternalMetaDiskStorPool(vlm);
}
DrbdVlmData<Resource> drbdVlmData = layerDataFactory.createDrbdVlmData(
vlm,
extMetaStorPool,
Expand Down Expand Up @@ -383,6 +393,30 @@ protected List<ChildResourceData> getChildRsc(
List<DeviceLayerKind> layerListRef
)
throws AccessDeniedException, InvalidKeyException
{
List<ChildResourceData> ret = new ArrayList<>();

if (isDrbdDiskless(rscDataRef))
{
ret.add(new ChildResourceData("", DeviceLayerKind.STORAGE));
}
else
{
ret.add(new ChildResourceData(""));
}

if (needsMetaData(rscDataRef, layerListRef))
{
ret.add(new ChildResourceData(DrbdRscData.SUFFIX_META, DeviceLayerKind.STORAGE));
}

return ret;
}

private boolean needsMetaData(
DrbdRscData<Resource> rscDataRef,
List<DeviceLayerKind> layerListRef
) throws AccessDeniedException
{
boolean allVlmsUseInternalMetaData = true;
Resource rsc = rscDataRef.getAbsResource();
Expand Down Expand Up @@ -410,20 +444,12 @@ protected List<ChildResourceData> getChildRsc(
}
}

List<ChildResourceData> ret = new ArrayList<>();
ret.add(new ChildResourceData("")); // always have data

boolean isNvmeBelow = layerListRef.contains(DeviceLayerKind.NVME);
boolean isNvmeInitiator = rscDataRef.getAbsResource().getStateFlags()
.isSet(apiCtx, Resource.Flags.NVME_INITIATOR);
boolean isDrbdDiskless = rsc.getStateFlags().isSet(apiCtx, Resource.Flags.DRBD_DISKLESS);

if (!allVlmsUseInternalMetaData && !isDrbdDiskless && (!isNvmeBelow || isNvmeInitiator))
{
ret.add(new ChildResourceData(DrbdRscData.SUFFIX_META, DeviceLayerKind.STORAGE));
}

return ret;
return !allVlmsUseInternalMetaData && !isDrbdDiskless && (!isNvmeBelow || isNvmeInitiator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ protected WritecacheVlmData<Resource> createVlmLayerData(
throws AccessDeniedException, DatabaseException, ValueOutOfRangeException, ExhaustedPoolException,
ValueInUseException, LinStorException
{

return layerDataFactory.createWritecacheVlmData(vlm, getCacheStorPool(vlm), writecacheRscData);
StorPool cacheStorPool = null;
if (needsCacheDevice(writecacheRscData, layerListRef))
{
cacheStorPool = getCacheStorPool(vlm);
}
return layerDataFactory.createWritecacheVlmData(vlm, cacheStorPool, writecacheRscData);
}

@Override
Expand All @@ -178,17 +182,24 @@ protected List<ChildResourceData> getChildRsc(
List<ChildResourceData> children = new ArrayList<>();
children.add(new ChildResourceData(WritecacheRscData.SUFFIX_DATA));

boolean isNvmeBelow = layerListRef.contains(DeviceLayerKind.NVME);
boolean isNvmeInitiator = rscDataRef.getAbsResource().getStateFlags()
.isSet(apiCtx, Resource.Flags.NVME_INITIATOR);
if (!isNvmeBelow || isNvmeInitiator)
if (needsCacheDevice(rscDataRef, layerListRef))
{
children.add(new ChildResourceData(WritecacheRscData.SUFFIX_CACHE, DeviceLayerKind.STORAGE));
}

return children;
}

private boolean needsCacheDevice(WritecacheRscData<Resource> rscDataRef, List<DeviceLayerKind> layerListRef)
throws AccessDeniedException
{
boolean isNvmeBelow = layerListRef.contains(DeviceLayerKind.NVME);
boolean isNvmeInitiator = rscDataRef.getAbsResource().getStateFlags()
.isSet(apiCtx, Resource.Flags.NVME_INITIATOR);
boolean needsCacheDevice = !isNvmeBelow || isNvmeInitiator;
return needsCacheDevice;
}

@Override
public StorPool getStorPool(Volume vlmRef, AbsRscLayerObject<Resource> childRef)
throws AccessDeniedException, InvalidKeyException, InvalidNameException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,14 @@ protected void createWritecacheVlm(
) throws AccessDeniedException, InvalidNameException
{
String cacheStorPoolNameStr = vlmPojo.getCacheStorPoolName();
StorPool cacheStorPool = vlmRef.getAbsResource().getNode().getStorPool(
apiCtx,
new StorPoolName(cacheStorPoolNameStr)
);
StorPool cacheStorPool = null;
if (cacheStorPoolNameStr != null && !cacheStorPoolNameStr.trim().isEmpty())
{
cacheStorPool = vlmRef.getAbsResource().getNode().getStorPool(
apiCtx,
new StorPoolName(cacheStorPoolNameStr)
);
}

WritecacheVlmData<Resource> writecacheVlmData = layerDataFactory.createWritecacheVlmData(
vlmRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,14 @@ protected void createWritecacheVlm(
) throws AccessDeniedException, InvalidNameException
{
String cacheStorPoolNameStr = vlmPojoRef.getCacheStorPoolName();
StorPool cacheStorPool = vlmRef.getAbsResource().getNode().getStorPool(
apiCtx,
new StorPoolName(cacheStorPoolNameStr)
);
StorPool cacheStorPool = null;
if (cacheStorPoolNameStr != null && !cacheStorPoolNameStr.trim().isEmpty())
{
cacheStorPool = vlmRef.getAbsResource().getNode().getStorPool(
apiCtx,
new StorPoolName(cacheStorPoolNameStr)
);
}

WritecacheVlmData<Snapshot> writecacheVlmData = layerDataFactory.createWritecacheVlmData(
vlmRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void prepare(
{
if (String.format(FORMAT_DEV_PATH, dmDev).equals(devicePath))
{
errorReporter.logTrace("Writecache: device exists: %s, nothing to do", devicePath);
exists = true;
break;
}
Expand All @@ -135,6 +136,10 @@ public void prepare(
vlmData.setIdentifier(identifier);
if (!exists)
{
errorReporter.logTrace(
"Writecache: device not found. Will be created for identifier: %s",
identifier
);
vlmData.setDevicePath(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,35 +188,40 @@ public void updateGrossSize(VlmProviderObject<Resource> vlmData)

long netSize = drbdVlmData.getUsableSize();

if (drbdVlmData.isUsingExternalMetaData())
boolean isDiskless = drbdVlmData.getRscLayerObject().getAbsResource().getStateFlags()
.isSet(workerCtx, Resource.Flags.DRBD_DISKLESS);
if (!isDiskless)
{
long extMdSize = new MetaData().getExternalMdSize(
netSize,
peerSlots,
DrbdLayer.FIXME_AL_STRIPES,
DrbdLayer.FIXME_AL_STRIPE_SIZE
);
drbdVlmData.setAllocatedSize(netSize + extMdSize); // rough estimation
if (drbdVlmData.isUsingExternalMetaData())
{
long extMdSize = new MetaData().getExternalMdSize(
netSize,
peerSlots,
DrbdLayer.FIXME_AL_STRIPES,
DrbdLayer.FIXME_AL_STRIPE_SIZE
);
drbdVlmData.setAllocatedSize(netSize + extMdSize); // rough estimation

drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_DATA).setUsableSize(netSize);
VlmProviderObject<Resource> metaChild = drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_META);
if (metaChild != null)
drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_DATA).setUsableSize(netSize);
VlmProviderObject<Resource> metaChild = drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_META);
if (metaChild != null)
{
// is null if we are nvme-traget while the drbd-ext-metadata stays on the initiator side
metaChild.setUsableSize(extMdSize);
}
}
else
{
// is null if we are nvme-traget while the drbd-ext-metadata stays on the initiator side
metaChild.setUsableSize(extMdSize);
long grossSize = new MetaData().getGrossSize(
netSize,
peerSlots,
DrbdLayer.FIXME_AL_STRIPES,
DrbdLayer.FIXME_AL_STRIPE_SIZE
);
drbdVlmData.setAllocatedSize(grossSize);
drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_DATA).setUsableSize(grossSize);
}
}
else
{
long grossSize = new MetaData().getGrossSize(
netSize,
peerSlots,
DrbdLayer.FIXME_AL_STRIPES,
DrbdLayer.FIXME_AL_STRIPE_SIZE
);
drbdVlmData.setAllocatedSize(grossSize);
drbdVlmData.getChildBySuffix(DrbdRscData.SUFFIX_DATA).setUsableSize(grossSize);
}
}
catch (InvalidKeyException | IllegalArgumentException | MinSizeException | MaxSizeException |
MinAlSizeException | MaxAlSizeException | AlStripesException | PeerCountException exc)
Expand Down
2 changes: 1 addition & 1 deletion server/proto/common/WritecacheRsc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ message WritecacheVlm
optional int64 allocated_size = 4;
optional int64 usable_size = 5;
optional string disk_state = 6;
required string cache_stor_pool_name = 7;
optional string cache_stor_pool_name = 7;
}

Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,7 @@ private static WritecacheVlm buildWritecacheVlm(WritecacheVlmPojo vlmPojo)
WritecacheVlm.Builder protoVlmBuilder = WritecacheVlm.newBuilder()
.setVlmNr(vlmPojo.getVlmNr())
.setAllocatedSize(vlmPojo.getAllocatedSize())
.setUsableSize(vlmPojo.getUsableSize())
.setCacheStorPoolName(vlmPojo.getCacheStorPoolName());
.setUsableSize(vlmPojo.getUsableSize());
if (vlmPojo.getDevicePath() != null)
{
protoVlmBuilder.setDevicePathData(vlmPojo.getDevicePath());
Expand All @@ -1453,6 +1452,10 @@ private static WritecacheVlm buildWritecacheVlm(WritecacheVlmPojo vlmPojo)
{
protoVlmBuilder.setDiskState(vlmPojo.getDiskState());
}
if (vlmPojo.getCacheStorPoolName() != null)
{
protoVlmBuilder.setCacheStorPoolName(vlmPojo.getCacheStorPoolName());
}

return protoVlmBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,10 @@ public VolumeApi getApiData(Long allocated, AccessContext accCtx) throws AccessD
{
AbsRscLayerObject<Resource> rscLayerObject = rscLayersToExpand.removeFirst();
VlmProviderObject<Resource> vlmProvider = rscLayerObject.getVlmLayerObjects().get(vlmNr);

if (vlmProvider != null)
{
// vlmProvider is null is a layer (like DRBD) does not need for all volumes backing vlmProvider
// vlmProvider is null as a layer (like DRBD) does not need for all volumes backing vlmProvider
// (like in the case of mixed internal and external meta-data)
layerDataList.add(
new Pair<>(
Expand All @@ -392,7 +393,7 @@ public VolumeApi getApiData(Long allocated, AccessContext accCtx) throws AccessD
}

// deprecated - only for compatibility with old versions
if (rscLayerObject.getResourceNameSuffix().isEmpty()) // for "" resources vlmProvider always have to exist
if (compatStorPool == null && rscLayerObject.getResourceNameSuffix().isEmpty())
{
compatStorPool = vlmProvider.getStorPool();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ public boolean isUsingExternalMetaData()
@Override
public String getBackingDevice()
{
return getChildBySuffix(DrbdRscData.SUFFIX_DATA).getDevicePath();
VlmProviderObject<RSC> childBySuffix = getChildBySuffix(DrbdRscData.SUFFIX_DATA);
String devicePath = null;
if (childBySuffix != null)
{
// null when diskless
devicePath = childBySuffix.getDevicePath();
}
return devicePath;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public WritecacheVlmPojo asPojo(AccessContext accCtxRef) throws AccessDeniedExce
getVlmNr().value,
devicePathData,
devicePathCache,
cacheStorPool.getName().displayValue,
cacheStorPool == null ? null : cacheStorPool.getName().displayValue,
allocatedSize,
usableSize,
diskState
Expand Down

0 comments on commit ddc51b7

Please sign in to comment.