sahlberg / libnfs-python

Python bindings for libnfs
GNU Lesser General Public License v2.1
64 stars 34 forks source link

Problem while getting mtime value for nfsdirent #11

Closed dhanumuli closed 8 years ago

dhanumuli commented 8 years ago

I've following code for reading NFS directory contents

python

import libnfs nfsh = libnfs.NFS('nfs:///folder1/') d = libnfs.new_NFSDirHandle() ret = libnfs.nfs_opendir(nfsh._nfs, '/', d) if ret == -libnfs.errno.ENOENT: raise IOError(libnfs.errno.ENOENT, 'No such file or directory'); d = libnfs.NFSDirHandle_value(d) dirEntry = libnfs.nfs_readdir(nfsh._nfs, d) print dirEntry.name abc --> attribute printed correctly print dirEntry.mtime <Swig Object of type 'struct timeval ' at 0x9aeb70>swig/python detected a memory leak of type 'struct timeval ', no destructor found.

I tried to access the mtime through various ways but was unable to do so. All other attributes except mtime, atime, ctime are printed correctly. For the time attributes only I get the above mentioned error.

Can you please help in understanding what's wrong here?

sahlberg commented 8 years ago

Linux uses st_atim.tv_sec and st_atim.tv_nsec instead of st_atime nowadays.

Try using those instead of st_atime

On Wed, Oct 5, 2016 at 12:33 AM, dhanumuli notifications@github.com wrote:

I've following code for reading NFS directory contents

python

import libnfs nfsh = libnfs.NFS('nfs:///folder1/') d = libnfs.new_NFSDirHandle() ret = libnfs.nfs_opendir(nfsh._nfs, '/', d) if ret == -libnfs.errno.ENOENT: raise IOError(libnfs.errno.ENOENT, 'No such file or directory'); d = libnfs.NFSDirHandle_value(d) dirEntry = libnfs.nfs_readdir(nfsh._nfs, d) print dirEntry.name abc --> attribute printed correctly print dirEntry.mtime swig/python detected a memory leak of type 'struct timeval *', no destructor found.

I tried to access the mtime through various ways but was unable to do so. All other attributes except mtime, atime, ctime are printed correctly. For the time attributes only I get the above mentioned error.

Can you please help in understanding what's wrong here?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sahlberg/libnfs-python/issues/11, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeNkP0lVjHX-WoCAp8b2-Bf_dyM6kTnks5qw1KsgaJpZM4KOf4Q .

dhanumuli commented 8 years ago

I don't think the problem is with st_atime.

I modified libnfs.i code to return atime.tv_sec directly instead of struct timeval (changed datatype of atime in struct nfsdirent from struct timeval to uint64_t). Made the corresponding change in C libnfs library code also.

My modified code prints the tv_sec value correctly (through atime directly). It is only when struct timeval atime value is tried to access in python, I hit the " swig/python detected a memory leak of type 'struct timeval *', no destructor found." error and no value is printed. Trying to print atime.tv_sec, atime.seconds also fails. dir() on atime also does not give any useful field which can return tv_sec value.

dhanumuli commented 8 years ago

I tried with ubuntu 12.04 LTS and I am getting the same error as earlier. Your original documentation mentions that you have tested on ubuntu 10 but I am not sure whether it will work on ubuntu 10 as well.

From this link, I think the problem could be returning a struct instead of struct pointer (for atime, mtime, ctime). I could be wrong so can you please confirm?

Once problem is confirmed, I can work on the fix. I tried changing struct timeval for atime to struct timeval * atime but it is giving segmentation fault. Debugging it further.

dhanumuli commented 8 years ago

Referring to my last comment, when I included struct timedef definition in libnfs.i file, my code works absolutely fine (gives correct values of struct timeval atime, mtime and ctime).

However, the problem there is, tv_sec and tv_usec in struct timeval are defined as time_t and __suseconds_t which are defined as SLONGWORD_TYPE which is defined in sys/types.h as

define __SLONGWORD_TYPE long int

To make the code work, i've defined struct timeval in libnfs.i as follows struct timeval { long int tv_sec; long int tv_usec; }; which cannot be acceptable due to porting and compatibility.

Any pointers to how this can be solved?

sahlberg commented 8 years ago

On Tue, Oct 18, 2016 at 12:18 AM, dhanumuli notifications@github.com wrote:

Referring to my last comment, when I included struct timedef definition in libnfs.i file, my code works absolutely fine (gives correct values of struct timeval atime, mtime and ctime).

However, the problem there is, tv_sec and tv_usec in struct timeval are defined as time_t and __suseconds_t which are defined as SLONGWORD_TYPE which is defined in sys/types.h as

define __SLONGWORD_TYPE long int

To make the code work, i've defined struct timeval in libnfs.i as follows struct timeval { long int tv_sec; long int tv_usec; }; which cannot be acceptable due to porting and compatibility.

Maybe this is what needs to be done. Please send me a pull request for this and I will merge and try to figure ut what to do about other platforms.

Can you also try out the utils/nfs-ls.py tool and see how it works ?

Any pointers to how this can be solved?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sahlberg/libnfs-python/issues/11#issuecomment-254426664, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeNkOk3wT81Vq9vT80NpnQfPmq22_hmks5q1HLGgaJpZM4KOf4Q .

dhanumuli commented 8 years ago

I've already submitted pull request for the same #12

sahlberg commented 8 years ago

Merged