plfs / plfs-core

LANL no longer develops PLFS. Feel free to fork and develop as you wish.
41 stars 36 forks source link

Link problem using plfs_setxattr #329

Closed hadimontakhabi closed 10 years ago

hadimontakhabi commented 10 years ago

Compiling the following code with: gcc -L/opt/plfs/lib/ -lplfs plfs_simple_example.c -o plfs_simple_example -g -Wall -I/opt/plfs/include/ returns: /tmp/cc478ye6.o: In function main': /mnt/plfs/plfs_example/plfs_simple_example.c:47: undefined reference toplfs_setxattr' collect2: error: ld returned 1 exit status make: *\ [all] Error 1

Replacing plfs_setxattr function with plfs_getxattr doesn't produce the same problem! Anybody could help?

int main() { Plfs_fd pfd = NULL; char wpath[1024]; char buf; buf = "a"; int offset = 0; ssize_t bytes; char *filename; int flags; plfs_error_t plfs_ret;

filename = "filename.txt"; getcwd(wpath, sizeof(wpath)); sprintf(wpath,"%s/%s",wpath,filename); fprintf(stdout, "wpath: %s\n", wpath);

plfs_open( &pfd, wpath, O_CREAT | O_WRONLY | O_RDONLY, 0, 0666, NULL ); plfs_write( pfd, buf, sizeof(char), offset, 0, &bytes );

char *key; int value = 16; key = "num_hostdirs";

plfs_ret = plfs_setxattr(pfd, &value, key);
if (plfs_ret != PLFS_SUCCESS) { printf("ERROR in plf_setxattr:\n%s\n", strplfserr(plfs_ret)); }

plfs_ret = plfs_close(pfd, 0, 0, O_CREAT | O_WRONLY | O_RDONLY ,NULL, &flags); return 0; }

brettkettering commented 10 years ago

The only thing that I can think of is that it's not matching the function prototype because of your declaration of "char *key". I think it would want a string constant that is the xattr you want to set. So, you need:

char key[] = "MyKeyName";

Then, pass key as you do now.

Brett

From: hadimontakhabi notifications@github.com<mailto:notifications@github.com> Reply-To: plfs/plfs-core reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, December 5, 2013 11:49 AM To: plfs/plfs-core plfs-core@noreply.github.com<mailto:plfs-core@noreply.github.com> Subject: [plfs-core] Link problem using plfs_setxattr (#329)

Compiling the following code with: gcc -L/opt/plfs/lib/ -lplfs plfs_simple_example.c -o plfs_simple_example -g -Wall -I/opt/plfs/include/ returns: /tmp/cc478ye6.o: In function main': /mnt/plfs/plfs_example/plfs_simple_example.c:47: undefined reference toplfs_setxattr' collect2: error: ld returned 1 exit status make: *\ [all] Error 1

Replacing plfs_setxattr function with plfs_getxattr doesn't produce the same problem! Anybody could help?

int main() { Plfs_fd pfd = NULL; char wpath[1024]; char buf; buf = "a"; int offset = 0; ssize_t bytes; char *filename; int flags; plfs_error_t plfs_ret;

filename = "filename.txt"; getcwd(wpath, sizeof(wpath)); sprintf(wpath,"%s/%s",wpath,filename); fprintf(stdout, "wpath: %s\n", wpath);

plfs_open( &pfd, wpath, O_CREAT | O_WRONLY | O_RDONLY, 0, 0666, NULL ); plfs_write( pfd, buf, sizeof(char), offset, 0, &bytes );

char *key; int value = 16; key = "num_hostdirs";

plfs_ret = plfs_setxattr(pfd, &value, key);

if (plfs_ret != PLFS_SUCCESS) { printf("ERROR in plf_setxattr:\n%s\n", strplfserr(plfs_ret)); }

plfs_ret = plfs_close(pfd, 0, 0, O_CREAT | O_WRONLY | O_RDONLY ,NULL, &flags); return 0; }

— Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/329.

hadimontakhabi commented 10 years ago

Didn't make any difference!

brettkettering commented 10 years ago

I'm just guessing at how picky the compiler is being now. The function prototype from plfs.h is:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

So how about declaring:

const char key[] = "num_hostdirs"; const int value = 16;

Then call:

plfs_ret = plfs_setxattr(pfd, &value, key);

Other than that, I'd grep through the libplfs file and see if you see "plfs_setxatter" in there.

hadimontakhabi commented 10 years ago

Well, adding const for value and key didn't help. When I grep libplfs file, it does find this:

hadi@shiner:/opt/plfs/lib> grep plfs_setxattr libplfs.a Binary file libplfs.a matches

On Thu, Dec 5, 2013 at 1:20 PM, Brett Kettering notifications@github.comwrote:

I'm just guessing at how picky the compiler is being now. The function prototype from plfs.h is:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

So how about declaring:

const char key[] = "num_hostdirs"; const int value = 16;

Then call:

plfs_ret = plfs_setxattr(pfd, &value, key);

Other than that, I'd grep through the libplfs file and see if you see "plfs_setxatter" in there.

— Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/329#issuecomment-29928380 .

chuckcranor commented 10 years ago

On Thu, Dec 05, 2013 at 11:26:01AM -0800, hadimontakhabi wrote:

Well, adding const for value and key didn't help. When I grep libplfs file, it does find this:

hadi@shiner:/opt/plfs/lib> grep plfs_setxattr libplfs.a Binary file libplfs.a matches

what you really want to do is:

p9ea0[143]> nm lib/libplfs.a | grep plfs_setxattr 0000000000000919 T _Z13plfs_setxattrP7Plfs_fdPKvPKcm 0000000000000032 r _ZZ13plfs_setxattrP7Plfs_fdPKvPKcmE12FUNCTION p9ea0[144]>

C++ damage. something didn't get in an a extern "C" properly. note that plfs_getxattr doesn't have the problem.

p9ea0[144]> nm lib/libplfs.a | grep plfs_getxattr 0000000000000040 r _ZZ13plfs_getxattrE12FUNCTION 0000000000000a7a T plfs_getxattr p9ea0[145]>

chuck

hadimontakhabi commented 10 years ago

Chuck, that's exactly what I have in my case as well.

chuckcranor commented 10 years ago

the prototype in plfs.h.in is wrong:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

should be:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key, size_t len) ^^^^^^^^^^

an uncaught error when the plfs_error_t was put in the API.

chuck

brettkettering commented 10 years ago

I was just playing with nm and objdump too.

So, what you're saying is that plfs_setxattr needs to have a size_t len argument and then rebuild PLFS? If so, will you document that in an issue and make the change?

Thanks Chuck!

Brett

From: chuckcranor notifications@github.com<mailto:notifications@github.com> Reply-To: plfs/plfs-core reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, December 5, 2013 12:36 PM To: plfs/plfs-core plfs-core@noreply.github.com<mailto:plfs-core@noreply.github.com> Cc: Brett Kettering brettk@lanl.gov<mailto:brettk@lanl.gov> Subject: Re: [plfs-core] Link problem using plfs_setxattr (#329)

the prototype in plfs.h.in is wrong:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

should be:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key, size_t len) ^^^^^^^^^^

an uncaught error when the plfs_error_t was put in the API.

chuck

— Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/329#issuecomment-29929948.

brettkettering commented 10 years ago

Ah, I didn't look at the plfs.cpp file where it has this function prototype:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key, size_t len) {

Wow, how I miss strongly-typed languages. This would never have gotten past an Ada compiler. :-)

Let's just use this issue and fix the plfs.h.in file.

Chuck: I haven't kept my local repo up-to-date. If you have, will you make the fix?

Thanks, Brett

From: chuckcranor notifications@github.com<mailto:notifications@github.com> Reply-To: plfs/plfs-core reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, December 5, 2013 12:36 PM To: plfs/plfs-core plfs-core@noreply.github.com<mailto:plfs-core@noreply.github.com> Cc: Brett Kettering brettk@lanl.gov<mailto:brettk@lanl.gov> Subject: Re: [plfs-core] Link problem using plfs_setxattr (#329)

the prototype in plfs.h.in is wrong:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

should be:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key, size_t len) ^^^^^^^^^^

an uncaught error when the plfs_error_t was put in the API.

chuck

— Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/329#issuecomment-29929948.

chuckcranor commented 10 years ago

On Thu, Dec 05, 2013 at 11:44:21AM -0800, Brett Kettering wrote:

Chuck: I haven't kept my local repo up-to-date. If you have, will you make the fix?

ok.

chuck

Thanks, Brett

From: chuckcranor notifications@github.com<mailto:notifications@github.com> Reply-To: plfs/plfs-core reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, December 5, 2013 12:36 PM To: plfs/plfs-core plfs-core@noreply.github.com<mailto:plfs-core@noreply.github.com> Cc: Brett Kettering brettk@lanl.gov<mailto:brettk@lanl.gov> Subject: Re: [plfs-core] Link problem using plfs_setxattr (#329)

the prototype in plfs.h.in is wrong:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key);

should be:

plfs_error_t plfs_setxattr(Plfs_fd fd, const void value, const char *key, size_t len) ^^^^^^^^^^

an uncaught error when the plfs_error_t was put in the API.

chuck

? Reply to this email directly or view it on GitHubhttps://github.com/plfs/plfs-core/issues/329#issuecomment-29929948.


Reply to this email directly or view it on GitHub: https://github.com/plfs/plfs-core/issues/329#issuecomment-29930674

chuckcranor commented 10 years ago

On Thu, Dec 05, 2013 at 11:44:21AM -0800, Brett Kettering wrote:

Chuck: I haven't kept my local repo up-to-date. If you have, will you make the fix?

I did a pull request: https://github.com/plfs/plfs-core/pull/330

p9ea0[86]> nm lib/libplfs.a | fgrep ' T ' | grep plfs_ | grep xattr 0000000000000a7a T plfs_getxattr 0000000000000919 T plfs_setxattr p9ea0[87]>

chuck

hadimontakhabi commented 10 years ago

Thanks.