mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
fix(test): fall back to default direct I/O requirements in tests when statx isn't supported by using a higher lever util
Signed-off-by: machine424 <ayoubmrini424@gmail.com>
This commit is contained in:
parent
ab1b1db128
commit
5ac1e6a656
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// the defaults are deliberately set higher to cover most setups.
|
// the defaults are deliberately set higher to cover most setups.
|
||||||
// On Linux >= 6.14, statx(2) https://man7.org/linux/man-pages/man2/statx.2.html will be later
|
// On Linux >= 6.1, statx(2) https://man7.org/linux/man-pages/man2/statx.2.html will be later
|
||||||
// used to fetch the exact alignment restrictions.
|
// used to fetch the exact alignment restrictions.
|
||||||
defaultAlignment = 4096
|
defaultAlignment = 4096
|
||||||
defaultBufSize = 4096
|
defaultBufSize = 4096
|
||||||
@ -249,8 +249,10 @@ func (b *directIOWriter) Reset(f *os.File) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fileDirectIORqmts fetches alignment requirements via Statx, falling back to default
|
||||||
|
// values when unsupported.
|
||||||
func fileDirectIORqmts(f *os.File) (*directIORqmts, error) {
|
func fileDirectIORqmts(f *os.File) (*directIORqmts, error) {
|
||||||
alignmentRqmts, err := fetchDirectIORqmts(f.Fd())
|
alignmentRqmts, err := fetchDirectIORqmtsFromStatx(f.Fd())
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, errStatxNotSupported):
|
case errors.Is(err, errStatxNotSupported):
|
||||||
alignmentRqmts = defaultDirectIORqmts()
|
alignmentRqmts = defaultDirectIORqmts()
|
||||||
@ -378,9 +380,9 @@ func defaultDirectIORqmts() *directIORqmts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchDirectIORqmts retrieves direct I/O alignment requirements for a file descriptor using statx
|
// fetchDirectIORqmtsFromStatx tries to retrieve direct I/O alignment requirements for the
|
||||||
// when possible.
|
// file descriptor using statx.
|
||||||
func fetchDirectIORqmts(fd uintptr) (*directIORqmts, error) {
|
func fetchDirectIORqmtsFromStatx(fd uintptr) (*directIORqmts, error) {
|
||||||
var stat unix.Statx_t
|
var stat unix.Statx_t
|
||||||
flags := unix.AT_SYMLINK_NOFOLLOW | unix.AT_EMPTY_PATH | unix.AT_STATX_DONT_SYNC
|
flags := unix.AT_SYMLINK_NOFOLLOW | unix.AT_EMPTY_PATH | unix.AT_STATX_DONT_SYNC
|
||||||
mask := unix.STATX_DIOALIGN
|
mask := unix.STATX_DIOALIGN
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
func directIORqmtsForTest(tb testing.TB) *directIORqmts {
|
func directIORqmtsForTest(tb testing.TB) *directIORqmts {
|
||||||
f, err := os.OpenFile(path.Join(tb.TempDir(), "foo"), os.O_CREATE|os.O_WRONLY, 0o666)
|
f, err := os.OpenFile(path.Join(tb.TempDir(), "foo"), os.O_CREATE|os.O_WRONLY, 0o666)
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
alignmentRqmts, err := fetchDirectIORqmts(f.Fd())
|
alignmentRqmts, err := fileDirectIORqmts(f)
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
return alignmentRqmts
|
return alignmentRqmts
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user