pmqs / IO-Compress

IO-Compress - Perl5 module to read/write compressed data in multiple formats
14 stars 16 forks source link

cz-14gzopen.t fails on AFS filesystem #56

Open djzhh opened 6 months ago

djzhh commented 6 months ago

Test fails for perl-5.36.3 and perl-5.38.2 (no other versions tested) when compiling in an AFS-part of the filesystem. Compiling in e.g. /var/tmp works fine, though. ./Configure detects that the sources reside in AFS: AFS may be running... I'll be extra cautious then...

The errors detected are:

cpan/IO-Compress/t/cz-14gzopen ................................... #   Failed test '  gzopen returns undef'
#   at t/cz-14gzopen.t line 506.
#   Failed test '  gzerrno ok'
#   at t/cz-14gzopen.t line 507.
#  gzerrno 0
#   Failed test '  gzopen returns undef'
#   at t/cz-14gzopen.t line 528.
#   Failed test '  gzerrno ok'
#   at t/cz-14gzopen.t line 529.
# Looks like you failed 4 tests of 264.
FAILED at test 182

They correspond directly to tests using chmod (line numbers at the beginning):

    488     title 'read/write a non-readable/writable file';
...
    497         chmod 0444, $name
...
    506         ok !$fil, "  gzopen returns undef" ;
    507         ok $gzerrno, "  gzerrno ok" or
...

    520         chmod 0222, $name ;
...
    528         ok !$fil, "  gzopen returns undef" ;
    529         ok $gzerrno, "  gzerrno ok";

The tests must fail as there is no such thing as file-based ACLs in AFS; see https://docs.openafs.org/UserGuide/HDRWQ46.html

I assume that these tests should be skipped when compiled in an AFS-directory as a workaround.

Just for completeness:

% pwd
/afs/CELL/user/X/XXXXX

% /usr/bin/fs  version
auristor 2021.05
  Platform:
    osname=linux
    osvers=5.14.0-362.13.1.el9_3.x86_64
    archname=x86_64-linux
    uname='linux SOME-HOST.XXX.XXX 5.14.0-362.13.1.el9_3.x86_64 #1 smp preempt_dynamic thu dec 21 07:12:43 est 2023 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dafs=true'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='11.4.1 20230605 (Red Hat 11.4.1-2)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /usr/lib64 /usr/local/lib64
    libs=-lpthread -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
    libc=/lib/../lib64/libc.so.6
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.34'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'
pmqs commented 6 months ago

Interesting. This test has existed for a very very very long time so I'm surprised nobody has tripped over this issue before.

I need to add a preliminary test that checks that chmod actually works. If it doesn't these tests get skipped.

djzhh commented 6 months ago

Be aware that when using chmod the output of ls changes:

% systemctl status afs.mount
● afs.mount - /afs
     Loaded: loaded (/proc/self/mountinfo)
     Active: active (mounted) since Fri 2024-01-19 13:28:15 CET; 1 month 16 days ago
      Until: Fri 2024-01-19 13:28:15 CET; 1 month 16 days ago
      Where: /afs
       What: AFS

% mkdir demo
% cd demo

% fs listacl -path .
Access list for . is
Normal rights:
  username rlidwka
  system:administrators rlidwka
  system:anyuser l

% echo Hello World > a_file

% ls -ld a_file
-rw-r--r--. 1 username grp 12 Mar  6 02:34 a_file

% cat a_file
Hello World

% chmod 0000 a_file

% ls -ld a_file
----------. 1 username grp 12 Mar  6 02:34 a_file

% getfacl a_file
# file: a_file
# owner: username
# group: grp
user::---
group::---
other::---

% cat a_file
Hello World
pmqs commented 6 months ago

@djzhh Just looking at how I have the failing tests structure, I already do tests that check that the files I'm going to use are not-writable and not-readable respectively.

For example, for the non-writable use case I do this

        chmod 0444, $name
            or skip "Cannot create non-writable file", 3 ;

        skip "Cannot create non-writable file", 3
            if -w $name ;

        ok ! -w $name, "  input file not writable";

Once the code above runs successfully Perl thinks that the file $name is not writable, but the subsequent code that will write to the file does not fail for the AFS use case. That means that the -w operator isn't telling the truth.

Think my best option is to try to write data to the non-writable file and read data from the non-readable file.

Below is a proposed change for the two failing tests. If you have the time, could you give them a go with your AFS setup please?

{
    title 'read/write a non-readable/writable file';

    SKIP:
    {
        skip "Cannot create non-writable file", 3
            if $^O eq 'cygwin';

        my $lex = LexFile->new( my $name );
        writeFile($name, "abc");
        chmod 0444, $name
            or skip "Cannot create non-writable file", 3 ;

        skip "Cannot create non-writable file", 3
            if -w $name ;

        # double check non-writable for AFS
        my $written = do {
                        no warnings;
                        my $fh;
                        open $fh, '>', $name &&
                        print $fh "hello world"
                    };

        skip "Cannot create non-writable file", 3
            if $written ;

        ok ! -w $name, "  input file not writable";

        my $fil = gzopen($name, "wb") ;
        ok !$fil, "  gzopen returns undef" ;
        ok $gzerrno, "  gzerrno ok" or
            diag " gzerrno $gzerrno\n";

        chmod 0777, $name ;
    }

    SKIP:
    {
        my $lex = LexFile->new( my $name );
        skip "Cannot create non-readable file", 3
            if $^O eq 'cygwin';

        writeFile($name, "abc");
        chmod 0222, $name ;

        skip "Cannot create non-readable file", 3
            if -r $name ;

        # double check non-readable for AFS
        my $readable = do {
                        no warnings;
                        my $fh;
                        open $fh, '<', $name &&
                        read $fh, my $data, 1
                    };

        skip "Cannot create non-writable file", 3
            if $readable ;

        ok ! -r $name, "  input file not readable";
        $gzerrno = 0;
        my $fil = gzopen($name, "rb") ;
        ok !$fil, "  gzopen returns undef" ;
        ok $gzerrno, "  gzerrno ok";
        chmod 0777, $name ;
    }

}
djzhh commented 6 months ago

The test does not complain any longer. Thanks a lot, esp. as compiling in AFS is not so common.

pmqs commented 6 months ago

The test does not complain any longer.

Good job!

Thanks a lot, esp. as compiling in AFS is not so common.

I know of AFS, but I've never used it.