func (s *BlockVolume) getOrCreateBlockINode(ref torus.INodeRef) (*models.INode, error) { if ref.Volume() != torus.VolumeID(s.volume.Id) { panic("ids managed by metadata didn't match, how is that possible?") } if ref.INode != 1 { return s.srv.INodes.GetINode(s.getContext(), ref) } globals, err := s.mds.GlobalMetadata() if err != nil { } bs, err := blockset.CreateBlocksetFromSpec(globals.DefaultBlockSpec, nil) if err != nil { return nil, err } nBlocks := (s.volume.MaxBytes / globals.BlockSize) if s.volume.MaxBytes%globals.BlockSize != 0 { nBlocks++ } err = bs.Truncate(int(nBlocks), globals.BlockSize) if err != nil { return nil, err } inode := models.NewEmptyINode() inode.INode = 1 inode.Volume = s.volume.Id inode.Filesize = s.volume.MaxBytes inode.Blocks, err = torus.MarshalBlocksetToProto(bs) return inode, err }
func (b *blockEtcd) SyncINode(inode torus.INodeRef) error { vid := uint64(inode.Volume()) inodeBytes := string(inode.ToBytes()) k := etcd.MkKey("volumemeta", etcd.Uint64ToHex(vid), "blocklock") tx := b.Etcd.Client.Txn(b.getContext()).If( etcdv3.Compare(etcdv3.Version(k), ">", 0), etcdv3.Compare(etcdv3.Value(k), "=", b.Etcd.UUID()), ).Then( etcdv3.OpPut(etcd.MkKey("volumemeta", etcd.Uint64ToHex(vid), "blockinode"), inodeBytes), ) resp, err := tx.Commit() if err != nil { return err } if !resp.Succeeded { return torus.ErrLocked } return nil }