@@ -119,7 +119,7 @@ func New(ctx *context.Context, cfg Config) (manager Manager, err error) {
119
119
return
120
120
}
121
121
122
- func (m Manager ) List (ctx * context.Context ) (volumes []Volume , err error ) {
122
+ func (m Manager ) List (ctx * context.Context ) (volumes []string , err error ) {
123
123
// tracing
124
124
ctx = ctx .
125
125
Field (":func" , "manager/List" )
@@ -149,11 +149,9 @@ func (m Manager) List(ctx *context.Context) (volumes []Volume, err error) {
149
149
// read data dir
150
150
var files []os.FileInfo
151
151
{
152
- ctx := ctx .
153
- Field ("data-dir" , m .dataDir )
154
-
155
152
ctx .
156
153
Level (context .Trace ).
154
+ Field ("data-dir" , m .dataDir ).
157
155
Message ("checking if data-dir exists" )
158
156
159
157
_ , err = os .Stat (m .dataDir )
@@ -187,15 +185,8 @@ func (m Manager) List(ctx *context.Context) (volumes []Volume, err error) {
187
185
Message ("processing entry" )
188
186
189
187
if file .Mode ().IsRegular () {
190
- var vol Volume
191
-
192
- name := strings .TrimSuffix (file .Name (), filepath .Ext (file .Name ()))
193
- vol , err = m .getVolume (ctx .Derived (), name )
194
- if err != nil {
195
- return
196
- }
188
+ volumes = append (volumes , file .Name ())
197
189
198
- volumes = append (volumes , vol )
199
190
ctx .
200
191
Level (context .Trace ).
201
192
Message ("including as a volume" )
@@ -344,7 +335,7 @@ func (m Manager) Create(ctx *context.Context, name string, sizeInBytes int64, sp
344
335
}
345
336
346
337
// create data file
347
- var dataFilePath = filepath .Join (m .dataDir , name + "." + fs )
338
+ var dataFilePath = filepath .Join (m .dataDir , name )
348
339
{
349
340
ctx := ctx .
350
341
Field ("data-file" , dataFilePath ).
@@ -562,7 +553,7 @@ func (m Manager) Mount(ctx *context.Context, name string, lease string) (result
562
553
ctx .
563
554
Level (context .Trace ).
564
555
Message ("checking if volume is mounted anywhere else" )
565
- isAlreadyMounted , err = volume .IsMounted () // checking mount status early before we record a lease
556
+ isAlreadyMounted , err = volume .IsMounted (ctx . Derived () ) // checking mount status early before we record a lease
566
557
if err != nil {
567
558
err = errors .Wrap (err , "cannot check volume mount status" )
568
559
return
@@ -667,8 +658,18 @@ func (m Manager) Mount(ctx *context.Context, name string, lease string) (result
667
658
return
668
659
}
669
660
670
- // we should've validated FS by now if it's not found then we will get empty list of options
671
- mountFlags := MountOptions [volume .Fs ]
661
+ ctx .
662
+ Level (context .Trace ).
663
+ Message ("resolving volume fs to determine mount options" )
664
+ var fs string
665
+ fs , err = volume .Fs (ctx .Derived ())
666
+ if err != nil {
667
+ err = errors .Wrapf (err , "cannot resolve volume fs to determine mount options" )
668
+ return
669
+ }
670
+
671
+ mountFlags := MountOptions [fs ]
672
+
672
673
ctx .
673
674
Level (context .Trace ).
674
675
Field ("mount-flags" , mountFlags ).
@@ -678,6 +679,7 @@ func (m Manager) Mount(ctx *context.Context, name string, lease string) (result
678
679
"mount" ,
679
680
append (mountFlags , volume .DataFilePath , volume .MountPointPath )... ,
680
681
)
682
+
681
683
if err != nil {
682
684
ctx .
683
685
Level (context .Trace ).
@@ -768,7 +770,7 @@ func (m Manager) UnMount(ctx *context.Context, name string, lease string) (err e
768
770
ctx .
769
771
Level (context .Trace ).
770
772
Message ("checking if volume is mounted anywhere else" )
771
- isMountedAnywhereElse , err = volume .IsMounted ()
773
+ isMountedAnywhereElse , err = volume .IsMounted (ctx . Derived () )
772
774
if err != nil {
773
775
err = errors .Wrapf (err , "cannot figure out if volume is used anywhere else" , lease )
774
776
return
@@ -873,7 +875,7 @@ func (m Manager) Delete(ctx *context.Context, name string) (err error) {
873
875
Message ("checking if volume is still mounted" )
874
876
875
877
var isMounted bool
876
- isMounted , err = volume .IsMounted ()
878
+ isMounted , err = volume .IsMounted (ctx . Derived () )
877
879
878
880
if err != nil {
879
881
err = errors .Wrap (err , "cannot get volume mount status" )
@@ -929,36 +931,19 @@ func (m Manager) getVolume(ctx *context.Context, name string) (volume Volume, er
929
931
}()
930
932
}
931
933
932
- prefix := filepath .Join (m .dataDir , name ) + ".*"
933
- matches , err := filepath .Glob (prefix )
934
- if err != nil {
935
- err = errors .Wrapf (err ,
936
- "an issue occurred while retrieving details about volume '%s' - cannot glob data dir" , name )
937
- return
938
- }
939
- if len (matches ) > 1 {
940
- err = errors .Errorf ("more than 1 data file found for volume '%s'" , name )
941
- return
942
- } else if len (matches ) == 0 {
943
- err = errors .Errorf ("volume '%s' does not exist" , name )
944
- return
945
- }
946
-
947
- volumeDataFilePath := matches [0 ]
948
- fs := strings .TrimLeft (filepath .Ext (volumeDataFilePath ), "." )
949
-
934
+ volumeDataFilePath := filepath .Join (m .dataDir , name )
950
935
volumeDataFileInfo , err := os .Stat (volumeDataFilePath )
951
936
952
937
if err != nil {
953
- if os .IsNotExist (err ) { // this should not happen but...
954
- err = errors .Errorf ("volume '%s' disappeared just a moment ago " , name )
938
+ if os .IsNotExist (err ) {
939
+ err = errors .Errorf ("volume '%s' does not exist " , name )
955
940
}
956
941
return
957
942
}
958
943
959
944
if ! volumeDataFileInfo .Mode ().IsRegular () {
960
945
err = errors .Errorf (
961
- "volume data path expected to point to a file but it appears to be something else: '%s'" ,
946
+ "volume data path expected to point toa file but it appears to be something else: '%s'" ,
962
947
volumeDataFilePath )
963
948
return
964
949
}
@@ -974,7 +959,6 @@ func (m Manager) getVolume(ctx *context.Context, name string) (volume Volume, er
974
959
975
960
volume = Volume {
976
961
Name : name ,
977
- Fs : fs ,
978
962
AllocatedSizeInBytes : uint64 (details .Blocks * 512 ),
979
963
MaxSizeInBytes : uint64 (details .Size ),
980
964
StateDir : filepath .Join (m .stateDir , name ),
0 commit comments