Discussion:
[OpenZFS Developer] Naive doubt about printk in zfs code
Punit Mutha
2013-12-10 21:47:28 UTC
Permalink
hello,
i have a naive doubt about adding printk in zfs module.

i am trying to add debug statements in zfs code and

facing this weird compiler error.

.../../module/zfs/dmu.c: In function ‘dmu_object_size_from_db’:
.../../module/zfs/dmu.c:2006: error: ‘KERN_INFO’ undeclared (first use in
this function)
.../../module/zfs/dmu.c:2006: error: expected ‘)’ before string constant
.../../module/zfs/dmu.c:2018: error: expected ‘)’ before string constant

so it is complaining about usage of printk in dmu.c

but it didnt complained about printk usage in zvol.c

as far as i see there are no difference in compilation flags.

google search tells that i need to include /lib/modules in makefile..

but i think all arguments are same for zvol.c and that for dmu.c
Regards
Punit
Saso Kiselkov
2013-12-11 02:48:08 UTC
Permalink
Post by Punit Mutha
hello,
i have a naive doubt about adding printk in zfs module.
i am trying to add debug statements in zfs code and
facing this weird compiler error.
.../../module/zfs/dmu.c:2006: error: ‘KERN_INFO’ undeclared (first use
in this function)
.../../module/zfs/dmu.c:2006: error: expected ‘)’ before string constant
.../../module/zfs/dmu.c:2018: error: expected ‘)’ before string constant
so it is complaining about usage of printk in dmu.c
but it didnt complained about printk usage in zvol.c
as far as i see there are no difference in compilation flags.
google search tells that i need to include /lib/modules in makefile..
but i think all arguments are same for zvol.c and that for dmu.c
Hi Punit,

printk is Linux-specific and thus might not work well in the ZFS code
base (and will certainly break if ported onto other kernels). I
recommend either using cmn_err(9F) (this is Solaris-specific, but since
ZFS originated there, the Linux port already includes compatibility for
it)
[http://docs.oracle.com/cd/E19253-01/816-5180/cmn-err-9f/index.html],
or, if you're just debugging something, try to use dynamic tracer
instead, such as DTrace or SystemTap - this will save you a ton of time
rather than rerolling new kernel modules each time you've progressed in
your debugging process.

Quick addendum: cmn_err works exactly the same as printk, so these are
two equivalent statements:

printk(KERN_INFO, "Value of int is: %d\n", x);
cmn_err(CE_NOTE, "Value of int is: %d", x);

Notice that with cmn_err you don't need to add a \n at the end - it's
appended automatically.

Cheers,
--
Saso
Saso Kiselkov
2013-12-11 02:53:19 UTC
Permalink
Post by Saso Kiselkov
Post by Punit Mutha
hello,
i have a naive doubt about adding printk in zfs module.
i am trying to add debug statements in zfs code and
facing this weird compiler error.
.../../module/zfs/dmu.c:2006: error: ‘KERN_INFO’ undeclared (first use
in this function)
.../../module/zfs/dmu.c:2006: error: expected ‘)’ before string constant
.../../module/zfs/dmu.c:2018: error: expected ‘)’ before string constant
so it is complaining about usage of printk in dmu.c
but it didnt complained about printk usage in zvol.c
as far as i see there are no difference in compilation flags.
google search tells that i need to include /lib/modules in makefile..
but i think all arguments are same for zvol.c and that for dmu.c
Hi Punit,
printk is Linux-specific and thus might not work well in the ZFS code
base (and will certainly break if ported onto other kernels). I
recommend either using cmn_err(9F) (this is Solaris-specific, but since
ZFS originated there, the Linux port already includes compatibility for
it)
[http://docs.oracle.com/cd/E19253-01/816-5180/cmn-err-9f/index.html],
or, if you're just debugging something, try to use dynamic tracer
instead, such as DTrace or SystemTap - this will save you a ton of time
rather than rerolling new kernel modules each time you've progressed in
your debugging process.
Quick addendum: cmn_err works exactly the same as printk, so these are
printk(KERN_INFO, "Value of int is: %d\n", x);
cmn_err(CE_NOTE, "Value of int is: %d", x);
Notice that with cmn_err you don't need to add a \n at the end - it's
appended automatically.
Addendum #2: use CE_WARN instead of CE_NOTE. For some reason, the SPL is
implemented to ignore cmn_err calls with a level of CE_NOTE.

Cheers,
--
Saso
Ned Bass
2013-12-11 18:15:38 UTC
Permalink
I think those errors must come from the user-space build, which doesn't
know about printk. In source that is built in both kernel and user
space you generally need to surround printk's with

#ifdef _KERNEL
#endif

As Saso points out, cmn_err() is the appropriate debug message interface
if you wanted to get your patch merged. But for a throw-away debug
patch, printk may be more convenient on Linux because it avoids having
to deal with the SPL debug log infrastructure.

Ned
Post by Punit Mutha
hello,
i have a naive doubt about adding printk in zfs module.
i am trying to add debug statements in zfs code and
facing this weird compiler error.
.../../module/zfs/dmu.c:2006: error: ?KERN_INFO? undeclared (first use in this
function)
.../../module/zfs/dmu.c:2006: error: expected ?)? before string constant
.../../module/zfs/dmu.c:2018: error: expected ?)? before string constant
so it is complaining about usage of printk in dmu.c
but it didnt complained about printk usage in zvol.c
as far as i see there are no difference in compilation flags.
google search tells that i need to include /lib/modules in makefile..
but i think all arguments are same for zvol.c and that for dmu.c
Regards
Punit
_______________________________________________
developer mailing list
http://lists.open-zfs.org/mailman/listinfo/developer
Punit Mutha
2013-12-12 17:48:31 UTC
Permalink
Thank you all for your advice.
I will try to use cmn_err.
Also i tried using systemtap - but i dont know why it is not probing to
some of the functions.

e.g:
i tried following command : stap -d spl -e 'probe
module("z*").function("*[*.c]") {printf("Called ## %s ##\n", probefunc());
print_backtrace();}'

it printed many probes - but it didnt say that it called important
functions like : dmu_read_uio() (printk says it does call)
I am trying to understand how zfs pipeline works and how taskq_thread gets
work

Thanks a lot for help

Regards
Punit
Post by Ned Bass
I think those errors must come from the user-space build, which doesn't
know about printk. In source that is built in both kernel and user
space you generally need to surround printk's with
#ifdef _KERNEL
#endif
As Saso points out, cmn_err() is the appropriate debug message interface
if you wanted to get your patch merged. But for a throw-away debug
patch, printk may be more convenient on Linux because it avoids having
to deal with the SPL debug log infrastructure.
Ned
Post by Punit Mutha
hello,
i have a naive doubt about adding printk in zfs module.
i am trying to add debug statements in zfs code and
facing this weird compiler error.
.../../module/zfs/dmu.c:2006: error: ?KERN_INFO? undeclared (first use
in this
Post by Punit Mutha
function)
.../../module/zfs/dmu.c:2006: error: expected ?)? before string constant
.../../module/zfs/dmu.c:2018: error: expected ?)? before string constant
so it is complaining about usage of printk in dmu.c
but it didnt complained about printk usage in zvol.c
as far as i see there are no difference in compilation flags.
google search tells that i need to include /lib/modules in makefile..
but i think all arguments are same for zvol.c and that for dmu.c
Regards
Punit
_______________________________________________
developer mailing list
http://lists.open-zfs.org/mailman/listinfo/developer
Loading...