Fix #907 #917

Merged
lx merged 3 commits from vk/garage:fix_907 into main 2025-01-04 16:07:40 +00:00
Contributor

A naive fix for #907. Successfully tested on FreeBSD.

A naive fix for #907. Successfully tested on FreeBSD.
vk added 1 commit 2025-01-04 11:51:44 +00:00
Fix #907
Some checks failed
ci/woodpecker/pr/debug Pipeline failed
b568bb863d
vk added 1 commit 2025-01-04 13:46:48 +00:00
formatting
Some checks failed
ci/woodpecker/pr/debug Pipeline failed
6ca99fd02c
Author
Contributor

Would you guys mind taking a look and fixing the formatting, I have no clue what I'm doing wrong?

Would you guys mind taking a look and fixing the formatting, I have no clue what I'm doing wrong?
Owner

Did you try running cargo fmt from the root of the project? This should reformat the code as appropriate.

Did you try running `cargo fmt` from the root of the project? This should reformat the code as appropriate.
Owner

With this implementation, on FreeBSD we will now make two calls, one to statfs and one to statvfs. I think we can avoid this and also make the code simpler, by just making the current mount_avail function conditionnal to #[cfg(not(target_os="freebsd"))], and rewrite a freebsd-specific version that uses statfs instead of statvfs. This would avoid adding lines 850-860 and we can keep 843-848 as is on all platforms.

With this implementation, on FreeBSD we will now make two calls, one to statfs and one to statvfs. I think we can avoid this and also make the code simpler, by just making the current mount_avail function conditionnal to `#[cfg(not(target_os="freebsd"))]`, and rewrite a freebsd-specific version that uses statfs instead of statvfs. This would avoid adding lines 850-860 and we can keep 843-848 as is on all platforms.
Author
Contributor

With this implementation, on FreeBSD we will now make two calls, one to statfs and one to statvfs. I think we can avoid this and also make the code simpler, by just making the current mount_avail function conditionnal to #[cfg(not(target_os="freebsd"))], and rewrite a freebsd-specific version that uses statfs instead of statvfs. This would avoid adding lines 850-860 and we can keep 843-848 as is on all platforms.

Indeed, but that's intentional. statfs is deprecated on most platforms, by statvfs, which is furthermore part of the POSIX standard. Hence, statfs is being used barely as a workaround the filesystem_id issue. Moreover, IIRC (I'll check further), manipulating statfs results requires knowledge of the underlying filesystem (whether it's ufs, zfs, ...) in order to exploit the returned data, which is what statvfsdoes.

> With this implementation, on FreeBSD we will now make two calls, one to statfs and one to statvfs. I think we can avoid this and also make the code simpler, by just making the current mount_avail function conditionnal to `#[cfg(not(target_os="freebsd"))]`, and rewrite a freebsd-specific version that uses statfs instead of statvfs. This would avoid adding lines 850-860 and we can keep 843-848 as is on all platforms. Indeed, but that's intentional. `statfs` is deprecated on most platforms, by `statvfs`, which is furthermore part of the POSIX standard. Hence, `statfs` is being used barely as a workaround the `filesystem_id` issue. Moreover, IIRC (I'll check further), manipulating `statfs` results requires knowledge of the underlying filesystem (whether it's `ufs`, `zfs`, ...) in order to exploit the returned data, which is what `statvfs`does.
Owner

Ok, that's fine then!

If you give me write access to your forked repo I can run the correct cargo fmt command for you

Ok, that's fine then! If you give me write access to your forked repo I can run the correct cargo fmt command for you
Author
Contributor

It seems I was partly wrong, statvfs seems to barely copy the statfs results (it acts as a dumb wrapper).

static int
sfs2svfs(const struct statfs *from, struct statvfs *to)
{
        static const struct statvfs zvfs;

        *to = zvfs;

        if (from->f_flags & MNT_RDONLY)
                to->f_flag |= ST_RDONLY;
        if (from->f_flags & MNT_NOSUID)
                to->f_flag |= ST_NOSUID;

        /* XXX should we clamp negative values? */
#define COPY(field) \
        do { \
                to->field = from->field; \
                if (from->field != to->field) { \
                        errno = EOVERFLOW; \
                        return (-1); \
                } \
        } while(0)

        COPY(f_bavail);
        COPY(f_bfree);
        COPY(f_blocks);
        COPY(f_ffree);
        COPY(f_files);
        to->f_bsize = from->f_iosize;
        to->f_frsize = from->f_bsize;
        to->f_favail = to->f_ffree;
        return (0);
}

Yet, I'd still stick to using statfvs for its intended purpose, but I may refactor this as you decide.

It seems I was partly wrong, `statvfs` seems to barely copy the `statfs` results (it acts as a dumb wrapper). ``` static int sfs2svfs(const struct statfs *from, struct statvfs *to) { static const struct statvfs zvfs; *to = zvfs; if (from->f_flags & MNT_RDONLY) to->f_flag |= ST_RDONLY; if (from->f_flags & MNT_NOSUID) to->f_flag |= ST_NOSUID; /* XXX should we clamp negative values? */ #define COPY(field) \ do { \ to->field = from->field; \ if (from->field != to->field) { \ errno = EOVERFLOW; \ return (-1); \ } \ } while(0) COPY(f_bavail); COPY(f_bfree); COPY(f_blocks); COPY(f_ffree); COPY(f_files); to->f_bsize = from->f_iosize; to->f_frsize = from->f_bsize; to->f_favail = to->f_ffree; return (0); } ``` Yet, I'd still stick to using `statfvs` for its intended purpose, but I may refactor this as you decide.
Author
Contributor

Ok, that's fine then!

If you give me write access to your forked repo I can run the correct cargo fmt command for you

I'll do, but I'll still try doing it by myself. I'm a total noob in rust and tooling but I believe I can do that :)

> Ok, that's fine then! > > If you give me write access to your forked repo I can run the correct cargo fmt command for you I'll do, but I'll still try doing it by myself. I'm a total noob in rust and tooling but I believe I can do that :)
Author
Contributor

Ok, that's fine then!

If you give me write access to your forked repo I can run the correct cargo fmt command for you

I'll do, but I'll still try doing it by myself. I'm a total noob in rust and tooling but I believe I can do that :)

Ok, cargo fmt does reformat my patch but also other files I haven't touched, I'll push mine only, that okay?

> > Ok, that's fine then! > > > > If you give me write access to your forked repo I can run the correct cargo fmt command for you > > I'll do, but I'll still try doing it by myself. I'm a total noob in rust and tooling but I believe I can do that :) Ok, `cargo fmt` does reformat my patch but also other files I haven't touched, I'll push mine only, that okay?
vk added 1 commit 2025-01-04 15:52:28 +00:00
Formatting with
All checks were successful
ci/woodpecker/pr/debug Pipeline was successful
6689800986
Owner

LGTM, thanks for your contribution :)

LGTM, thanks for your contribution :)
lx merged commit 7bbc8fec50 into main 2025-01-04 16:07:40 +00:00
vk deleted branch fix_907 2025-01-04 16:11:10 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/garage#917
No description provided.