On 12/11/13, 2:48 AM, Saso Kiselkov wrote: > On 12/10/13, 9:47 PM, Punit Mutha wrote: >> 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 > > 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.
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 _______________________________________________ developer mailing list [email protected] http://lists.open-zfs.org/mailman/listinfo/developer
