From owner-freebsd-bugs@FreeBSD.ORG Wed Sep 24 12:00:07 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1427E1065683; Wed, 24 Sep 2008 12:00:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9865C8FC1C; Wed, 24 Sep 2008 12:00:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m8OC05m1009868; Wed, 24 Sep 2008 12:00:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m8OC056Q009867; Wed, 24 Sep 2008 12:00:05 GMT (envelope-from gnats) Resent-Date: Wed, 24 Sep 2008 12:00:05 GMT Resent-Message-Id: <200809241200.m8OC056Q009867@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@freebsd.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Cc: scottl@freebsd.org, marius@freebsd.org Resent-Reply-To: FreeBSD-gnats-submit@freebsd.org, Eygene Ryabinkin Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 028AE1065689 for ; Wed, 24 Sep 2008 11:50:21 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id AE4FE8FC0A for ; Wed, 24 Sep 2008 11:50:15 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from void.codelabs.ru (void.codelabs.ru [144.206.177.25]) by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256) id 1KiSso-000Ge9-Gs for FreeBSD-gnats-submit@freebsd.org; Wed, 24 Sep 2008 15:50:14 +0400 Message-Id: <20080924115014.4D2731AF41C@void.codelabs.ru> Date: Wed, 24 Sep 2008 15:50:14 +0400 (MSD) From: Eygene Ryabinkin To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 X-GNATS-Notify: scottl@freebsd.org, marius@freebsd.org Cc: Subject: bin/127605: [patch] properly initialise ccb_h.path_id in cam_open_btl (lib/libcam) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Eygene Ryabinkin List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Sep 2008 12:00:07 -0000 >Number: 127605 >Category: bin >Synopsis: [patch] properly initialise ccb_h.path_id in cam_open_btl (lib/libcam) >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Sep 24 12:00:05 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Eygene Ryabinkin >Release: FreeBSD 7.1-PRERELEASE i386 >Organization: Code Labs >Environment: System: FreeBSD XXX 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #19: Tue Sep 23 13:21:48 MSD 2008 root@XXX:/usr/src/sys/i386/compile/XXX i386 >Description: When I use cdrecord on the fresh 7.1-PRERELEASE, it fails to open the device (atapicam one in my case) saying ----- cdrecord: Invalid argument. Cannot open SCSI driver. ----- I had traced this to the calls for XPT_DEV_MATCH on /dev/xpt0 with ioctl(CAMIOCOMMAND) inside cam_open_btl() and it turned out that the ccb.ccb_h.path_id is not filled in. As I see, xptioctl in sys/cam/cam_xpt.c invokes xpt_find_bus passing path_id as an argument and returns EINVAL in case of error. >How-To-Repeat: For me it was sufficient to check out yesterday's (September 24th, 2008) 7.1-PRERELEASE, and spawn cdrecord on my recorder (IDE-connected PIONEER DVD-RW DVR-108 1.14, with atapicam emulation layer). cdrecord also fails to perform bus scanning with '-scanbus': is has simular code to enumerate devices via XPT_DEV_MATCH. But with old libcam and fixed enumeration code it successfully returns the list of devices, but fails to open any due to the problem in cam_open_btl(). Another way to reproduce the problem is to spawn 'camcontrol eject b:t:l' with unpatched libcam: ----- $ camcontrol eject 1:1:0 camcontrol: cam_open_btl: CAMIOCOMMAND ioctl failed cam_open_btl: Invalid argument ----- >Fix: The following patch cures the problem in the libcam: --- libcam-add-ids-for-XPT_DEV_MATCH.patch begins here --- CAMIOCOMMAND with argument XPT_DEV_MATCH fails with EINVAL if field ccb_h.path_id is not set to CAM_XPT_PATH_ID. I am additionally setting target_id and target_lun to the wildcard values. Had not found the exact specifications for what is needed for XPT_DEV_MATCH, but the code in the camcontrol.c sets all three fields. For the atapicam(4) CD-ROM device setting only ccb_h.path_id is sufficient to get cam_open_btl() working for cdrecord tool from sysutils/cdrtools [1]. But setting the other fields makes no harm here, so I really don't know if it is needed or not. [1] Needs patching too: it has the simular code for the bus scanning and no ccb_h.path_id was set there as well. Opened another PR. -- Eygene, rea-fbsd@codelabs.ru --- lib/libcam/camlib.c.orig 2008-09-24 14:56:25.000000000 +0400 +++ lib/libcam/camlib.c 2008-09-24 14:58:12.000000000 +0400 @@ -346,6 +346,9 @@ bzero(&ccb, sizeof(union ccb)); ccb.ccb_h.func_code = XPT_DEV_MATCH; + ccb.ccb_h.path_id = CAM_XPT_PATH_ID; + ccb.ccb_h.target_id = CAM_TARGET_WILDCARD; + ccb.ccb_h.target_lun = CAM_LUN_WILDCARD; /* Setup the result buffer */ bufsize = sizeof(struct dev_match_result); --- libcam-add-ids-for-XPT_DEV_MATCH.patch ends here --- As I said in the patch description, I am not completely sure that one should initialize all three fields, but it makes no harm for my test cases. Attaching the patch for the cdrecord here too, but it is just for the reference. I will open another PR and will try to contact Joerg Schilling: seems like this needs to be patched in upstream as well. --- patch-libscg::scsi-bsd.c begins here --- --- libscg/scsi-bsd.c.orig 2008-09-24 14:03:04.000000000 +0400 +++ libscg/scsi-bsd.c 2008-09-24 14:04:03.000000000 +0400 @@ -674,6 +674,9 @@ * system. */ ccb.ccb_h.func_code = XPT_DEV_MATCH; + ccb.ccb_h.path_id = CAM_XPT_PATH_ID; + ccb.ccb_h.target_id = CAM_TARGET_WILDCARD; + ccb.ccb_h.target_lun = CAM_LUN_WILDCARD; /* * Setup the result buffer. --- patch-libscg::scsi-bsd.c begins here --- With these two patches I have no problem in burning CDs and performing some basic commands via camcontrol on my CD unit. I have no idea why this popped only in 7.1-PRERELEASE: I see that the code that checks ccb_h.path_id is present since sys/cam/cam_xpt.c 1.176 that is 17 month old. May be the problem is somewhere else, but I don't see where it is. >Release-Note: >Audit-Trail: >Unformatted: