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 makeFile(name string, t *testing.T) (*torus.Server, *torus.File) { srv := torus.NewMemoryServer() vol := &models.Volume{ Name: name, Id: 3, Type: "test", } globals, err := srv.MDS.GlobalMetadata() if err != nil { t.Fatal(err) } bs, err := blockset.CreateBlocksetFromSpec(globals.DefaultBlockSpec, srv.Blocks) if err != nil { t.Fatal(err) } inode := models.NewEmptyINode() inode.INode = 1 inode.Volume = vol.Id inode.Blocks, err = torus.MarshalBlocksetToProto(bs) f, err := srv.CreateFile(vol, inode, bs) if err != nil { t.Fatal(err) } return srv, f }