json zhou
json zhou

Reputation: 11

what is SAM LUN format in iscsi protocol?

When I read the source code of SPDK, there are two forms of fmt_lun in the function spdk_scsi_lun_id_fmt_to_int. What do these two forms mean? and fmt_lun complies with the SAM LUN format,what is SAM LUN format?

uint64_t spdk_scsi_lun_id_int_to_fmt(int lun_id) { uint64_t fmt_lun, method;

if (SPDK_SCSI_DEV_MAX_LUN <= 0x0100) {
    /* below 256 */
    method = 0x00U;
    fmt_lun = (method & 0x03U) << 62;
    fmt_lun |= ((uint64_t)lun_id & 0x00ffU) << 48;
} else if (SPDK_SCSI_DEV_MAX_LUN <= 0x4000) {
    /* below 16384 */
    method = 0x01U;
    fmt_lun = (method & 0x03U) << 62;
    fmt_lun |= ((uint64_t)lun_id & 0x3fffU) << 48;
} else {
    /* XXX */
    fmt_lun = 0;
}

return fmt_lun;

}

Upvotes: 1

Views: 54

Answers (1)

Mike Andrews
Mike Andrews

Reputation: 3205

You'll get the best answer to your question by going to the original specification. You can obtain a copy of the SCSI Architecture Model spec from t10.org here: https://www.t10.org/members/w_sam5.htm. That's the "SAM" from the SAM LUN format.

SCSI has had to adapt to numerous advancements in computing hardware over the years. Back in the mid-1980's, even if you could predict how storage would change over the decades, the protocol itself still needed to be useful on the comparatively tiny computers of the day. And, so you see a lot of this kind of thing in the SCSI world, like you have with LUN encoding. At some point in time, there became a need for more than 256 LUNs. Thankfully, the engineers had built in an addressing method field from the beginning. Naturally, the first method was 0. To maintain compatibility with existing systems, they created method 1, which allows for up to 16,384 LUNs.

SAM-5 defines four different addressing methods:

  • 0: Peripheral device addressing method
  • 1: Flat space addressing method
  • 2: Logical unit addressing method
  • 3: Extended logical unit addressing method

I've only seen the first two out in the wild, but I'm sure there are devices out there that use methods 2 and 3.

Upvotes: 1

Related Questions