Bug 214874 - ctld daemon wrong lun_size value on i386
Summary: ctld daemon wrong lun_size value on i386
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-RELEASE
Hardware: i386 Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Keywords: patch
Depends on:
Reported: 2016-11-27 12:03 UTC by pprocacci
Modified: 2016-11-28 19:19 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description pprocacci 2016-11-27 12:03:47 UTC
# fgrep -B 2 10G /etc/ctl.conf
        lun 0 {
                blocksize 8192
                size 10G

# ctladm devlist
LUN Backend       Size (Blocks)   BS Serial Number    Device ID
  0 block                262144 8192 MYSERIAL   0     MYDEVID   0

A guess, but by the looks of it, the value here is I'm guessing -1.  Probably a return value from within the expand_number (-lutil) function or something along those lines.
Comment 1 pprocacci 2016-11-27 12:28:02 UTC
One last comment.  I added debugging information to track the lun length value and this is what I ended up with:

DEBUG:: in parse.y line 1034: 10737418240
DEBUG:: in ctld.c line 1501: 2147483648
DEBUG:: in ctld.c line 1503: 2147483648
DEBUG:: in parse.y line 1036: 10737418240

I'll do more debugging as time permits.
Comment 2 pprocacci 2016-11-28 03:14:18 UTC
sizeof(size_t) == 4
sizeof(uint64_t) == 8

The cast from uint64_t to size_t is killing the value.

This small patch fixes the problem, though I'm not sure what ill effects this may have.

diff -ur ctld.orig ctld
diff -ur ctld.orig/ctld.c ctld/ctld.c
--- ctld.orig/ctld.c    2016-11-27 22:12:27.525990000 -0500
+++ ctld/ctld.c 2016-11-27 22:09:25.798040000 -0500
@@ -1496,7 +1496,7 @@

-lun_set_size(struct lun *lun, size_t value)
+lun_set_size(struct lun *lun, uint64_t value)
        lun->l_size = value;
Only in ctld.orig: ctld.c.orig
diff -ur ctld.orig/ctld.h ctld/ctld.h
--- ctld.orig/ctld.h    2016-11-27 22:12:16.851553000 -0500
+++ ctld/ctld.h 2016-11-27 22:10:31.732258000 -0500
@@ -388,7 +388,7 @@
 void                   lun_set_path(struct lun *lun, const char *value);
 void                   lun_set_scsiname(struct lun *lun, const char *value);
 void                   lun_set_serial(struct lun *lun, const char *value);
-void                   lun_set_size(struct lun *lun, size_t value);
+void                   lun_set_size(struct lun *lun, uint64_t value);
 void                   lun_set_ctl_lun(struct lun *lun, uint32_t value);

 struct option          *option_new(struct options *os,