-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
save device type instead of caching it #2023
Changes from 5 commits
7130ddf
5f70f99
9f31b3d
7ab701d
6bf9234
ad6817b
59a30cc
c9417d8
71c0ce3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/rs/zerolog/log" | ||
"github.com/threefoldtech/zos/pkg" | ||
"github.com/threefoldtech/zos/pkg/gridtypes/zos" | ||
) | ||
|
||
|
@@ -68,10 +70,38 @@ func (i *DeviceInfo) Used() bool { | |
return len(i.Label) != 0 || len(i.Filesystem) != 0 | ||
} | ||
|
||
func (d *DeviceInfo) Type() (zos.DeviceType, error) { | ||
// DetectType returns the device type according to seektime | ||
func (d *DeviceInfo) DetectType() (zos.DeviceType, error) { | ||
return d.mgr.Seektime(context.Background(), d.Path) | ||
} | ||
|
||
// SetType sets the device type to the disk | ||
func (d *DeviceInfo) SetType(typ pkg.DeviceType) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we use zos.DeviceType? I'm not sure why we created that alias declaration DeviceType = DeviceType? |
||
if err := os.WriteFile(filepath.Join("/mnt", d.Name(), ".seektime"), []byte(typ), 0644); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's extract the first argument of WriteFile into a varilable to improve the readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I believe we shouldn't use |
||
return errors.Wrapf(err, "failed to store device type for '%s'", d.Name()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please include the full path as well so |
||
} | ||
|
||
return nil | ||
} | ||
|
||
// Type gets the device type from the disk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's expand the docstring, that's based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also i'm not sure of the behavior of the return type device, bool, err |
||
func (d *DeviceInfo) Type() (zos.DeviceType, bool, error) { | ||
data, err := os.ReadFile(filepath.Join("/mnt", d.Name(), ".seektime")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if os.IsNotExist(err) { | ||
return "", false, nil | ||
} | ||
|
||
if err != nil { | ||
rawdaGastan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "", false, err | ||
} | ||
|
||
if len(data) == 0 { | ||
return "", false, nil | ||
} | ||
|
||
return pkg.DeviceType(data), true, nil | ||
} | ||
|
||
func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error) { | ||
return d.mgr.Mountpoint(ctx, d.Path) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time for me to know about the seektime tool, maybe we can enhance it to include that it's an approximation too https://github.com/maxux/seektime not 100% correct