/** * Reads the existing extended attributes of an inode. * <p/> * Must be called while holding the FSDirectory read lock. * * @param inodeAttr INodeAttributes to read. * @return List<XAttr> <code>XAttr</code> list. */ public static List<XAttr> readINodeXAttrs(INodeAttributes inodeAttr) { XAttrFeature f = inodeAttr.getXAttrFeature(); return f == null ? new ArrayList<XAttr>(0) : f.getXAttrs(); }
/** * Save the batch's edeks to file xattrs. */ static void saveFileXAttrsForBatch(FSDirectory fsd, List<FileEdekInfo> batch) { assert fsd.getFSNamesystem().hasWriteLock(); assert !fsd.hasWriteLock(); if (batch != null && !batch.isEmpty()) { for (FileEdekInfo entry : batch) { final INode inode = fsd.getInode(entry.getInodeId()); // no dir lock, so inode could be removed. no-op if so. if (inode == null) { NameNode.LOG.info("Cannot find inode {}, skip saving xattr for" + " re-encryption", entry.getInodeId()); continue; } fsd.getEditLog().logSetXAttrs(inode.getFullPathName(), inode.getXAttrFeature().getXAttrs(), false); } } }
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f) { XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder(); for (XAttr a : f.getXAttrs()) { XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto. newBuilder(); int v = XAttrFormat.toInt(a); xAttrCompactBuilder.setName(v); if (a.getValue() != null) { xAttrCompactBuilder.setValue(PBHelperClient.getByteString(a.getValue())); } b.addXAttrs(xAttrCompactBuilder.build()); } return b; }
/** * Add create directory record to edit log */ public void logMkDir(String path, INode newNode) { PermissionStatus permissions = newNode.getPermissionStatus(); MkdirOp op = MkdirOp.getInstance(cache.get()) .setInodeId(newNode.getId()) .setPath(path) .setTimestamp(newNode.getModificationTime()) .setPermissionStatus(permissions); AclFeature f = newNode.getAclFeature(); if (f != null) { op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode)); } XAttrFeature x = newNode.getXAttrFeature(); if (x != null) { op.setXAttrs(x.getXAttrs()); } logEdit(op); }
/** * Reads the existing extended attributes of an inode. * <p/> * Must be called while holding the FSDirectory read lock. * * @param inodeAttr INodeAttributes to read. * @return List<XAttr> <code>XAttr</code> list. */ public static List<XAttr> readINodeXAttrs(INodeAttributes inodeAttr) { XAttrFeature f = inodeAttr.getXAttrFeature(); return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs(); }
/** * Reads the existing extended attributes of an inode. If the * inode does not have an <code>XAttr</code>, then this method * returns an empty list. * <p/> * Must be called while holding the FSDirectory read lock. * * @param inode INode to read * @param snapshotId * @return List<XAttr> <code>XAttr</code> list. */ public static List<XAttr> readINodeXAttrs(INode inode, int snapshotId) { XAttrFeature f = inode.getXAttrFeature(snapshotId); return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs(); }
/** * Reads the existing extended attributes of an inode. * <p/> * Must be called while holding the FSDirectory read lock. * * @param inodeAttr INodeAttributes to read. * @return List<XAttr> <code>XAttr</code> list. */ public static List<XAttr> readINodeXAttrs(INodeAttributes inodeAttr) { XAttrFeature f = inodeAttr.getXAttrFeature(); return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs(); }
@Override public byte getLocalStoragePolicyID() { XAttrFeature f = getXAttrFeature(); ImmutableList<XAttr> xattrs = f == null ? ImmutableList.<XAttr> of() : f .getXAttrs(); for (XAttr xattr : xattrs) { if (BlockStoragePolicySuite.isStoragePolicyXAttr(xattr)) { return (xattr.getValue())[0]; } } return ID_UNSPECIFIED; }
/** * Reads the existing extended attributes of an inode. If the * inode does not have an <code>XAttr</code>, then this method * returns an empty list. * <p/> * Must be called while holding the FSDirectory read lock. * * @param inode INode to read * @param snapshotId * @return List<XAttr> <code>XAttr</code> list. */ public static List<XAttr> readINodeXAttrs(INode inode, int snapshotId) { XAttrFeature f = inode.getXAttrFeature(snapshotId); return f == null ? ImmutableList.<XAttr> of() : f.getXAttrs(); }
op.setXAttrs(x.getXAttrs());
@Override public byte getLocalStoragePolicyID() { XAttrFeature f = getXAttrFeature(); ImmutableList<XAttr> xattrs = f == null ? ImmutableList.<XAttr> of() : f .getXAttrs(); for (XAttr xattr : xattrs) { if (BlockStoragePolicySuite.isStoragePolicyXAttr(xattr)) { return (xattr.getValue())[0]; } } return ID_UNSPECIFIED; }
private void addEncryptionZone(INodeWithAdditionalFields inode, XAttrFeature xaf) { if (xaf == null) { return; } final List<XAttr> xattrs = xaf.getXAttrs(); for (XAttr xattr : xattrs) { final String xaName = XAttrHelper.getPrefixName(xattr); if (CRYPTO_XATTR_ENCRYPTION_ZONE.equals(xaName)) { try { final HdfsProtos.ZoneEncryptionInfoProto ezProto = HdfsProtos.ZoneEncryptionInfoProto.parseFrom( xattr.getValue()); ezManager.unprotectedAddEncryptionZone(inode.getId(), PBHelper.convert(ezProto.getSuite()), PBHelper.convert(ezProto.getCryptoProtocolVersion()), ezProto.getKeyName()); } catch (InvalidProtocolBufferException e) { NameNode.LOG.warn("Error parsing protocol buffer of " + "EZ XAttr " + xattr.getName() + " dir:" + inode.getFullPathName()); } } } }
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f, final SaverContext.DeduplicationMap<String> stringMap) { XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder(); for (XAttr a : f.getXAttrs()) { XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto. newBuilder(); int nsOrd = a.getNameSpace().ordinal(); Preconditions.checkArgument(nsOrd < 8, "Too many namespaces."); int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET) | ((stringMap.getId(a.getName()) & XATTR_NAME_MASK) << XATTR_NAME_OFFSET); v |= (((nsOrd >> 2) & XATTR_NAMESPACE_EXT_MASK) << XATTR_NAMESPACE_EXT_OFFSET); xAttrCompactBuilder.setName(v); if (a.getValue() != null) { xAttrCompactBuilder.setValue(PBHelper.getByteString(a.getValue())); } b.addXAttrs(xAttrCompactBuilder.build()); } return b; }
/** * Add create directory record to edit log */ public void logMkDir(String path, INode newNode) { PermissionStatus permissions = newNode.getPermissionStatus(); MkdirOp op = MkdirOp.getInstance(cache.get()) .setInodeId(newNode.getId()) .setPath(path) .setTimestamp(newNode.getModificationTime()) .setPermissionStatus(permissions); AclFeature f = newNode.getAclFeature(); if (f != null) { op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode)); } XAttrFeature x = newNode.getXAttrFeature(); if (x != null) { op.setXAttrs(x.getXAttrs()); } logEdit(op); }
/** * Add create directory record to edit log */ public void logMkDir(String path, INode newNode) { PermissionStatus permissions = newNode.getPermissionStatus(); MkdirOp op = MkdirOp.getInstance(cache.get()) .setInodeId(newNode.getId()) .setPath(path) .setTimestamp(newNode.getModificationTime()) .setPermissionStatus(permissions); AclFeature f = newNode.getAclFeature(); if (f != null) { op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode)); } XAttrFeature x = newNode.getXAttrFeature(); if (x != null) { op.setXAttrs(x.getXAttrs()); } logEdit(op); }
private void addEncryptionZone(INodeWithAdditionalFields inode, XAttrFeature xaf) { if (xaf == null) { return; } final List<XAttr> xattrs = xaf.getXAttrs(); for (XAttr xattr : xattrs) { final String xaName = XAttrHelper.getPrefixName(xattr); if (CRYPTO_XATTR_ENCRYPTION_ZONE.equals(xaName)) { try { final HdfsProtos.ZoneEncryptionInfoProto ezProto = HdfsProtos.ZoneEncryptionInfoProto.parseFrom( xattr.getValue()); ezManager.unprotectedAddEncryptionZone(inode.getId(), PBHelper.convert(ezProto.getSuite()), PBHelper.convert(ezProto.getCryptoProtocolVersion()), ezProto.getKeyName()); } catch (InvalidProtocolBufferException e) { NameNode.LOG.warn("Error parsing protocol buffer of " + "EZ XAttr " + xattr.getName() + " dir:" + inode.getFullPathName()); } } } }
@Test public void testXAttrFeature() { replication = 3; preferredBlockSize = 128*1024*1024; INodeFile inf = createINodeFile(replication, preferredBlockSize); ImmutableList.Builder<XAttr> builder = new ImmutableList.Builder<XAttr>(); XAttr xAttr = new XAttr.Builder().setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(new byte[]{0x31, 0x32, 0x33}).build(); builder.add(xAttr); XAttrFeature f = new XAttrFeature(builder.build()); inf.addXAttrFeature(f); XAttrFeature f1 = inf.getXAttrFeature(); assertEquals(xAttr, f1.getXAttrs().get(0)); inf.removeXAttrFeature(); f1 = inf.getXAttrFeature(); assertEquals(f1, null); } }
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f, final SaverContext.DeduplicationMap<String> stringMap) { XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder(); for (XAttr a : f.getXAttrs()) { XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto. newBuilder(); int nsOrd = a.getNameSpace().ordinal(); Preconditions.checkArgument(nsOrd < 8, "Too many namespaces."); int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET) | ((stringMap.getId(a.getName()) & XATTR_NAME_MASK) << XATTR_NAME_OFFSET); v |= (((nsOrd >> 2) & XATTR_NAMESPACE_EXT_MASK) << XATTR_NAMESPACE_EXT_OFFSET); xAttrCompactBuilder.setName(v); if (a.getValue() != null) { xAttrCompactBuilder.setValue(PBHelper.getByteString(a.getValue())); } b.addXAttrs(xAttrCompactBuilder.build()); } return b; }
op.setXAttrs(x.getXAttrs());
op.setXAttrs(x.getXAttrs());