From patchwork Mon Feb 14 14:00:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Jezak X-Patchwork-Id: 83080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id A262EB71B1 for ; Tue, 15 Feb 2011 01:05:19 +1100 (EST) Received: from qmta05.westchester.pa.mail.comcast.net (qmta05.westchester.pa.mail.comcast.net [76.96.62.48]) by ozlabs.org (Postfix) with ESMTP id 3A0EBB7198 for ; Tue, 15 Feb 2011 01:05:10 +1100 (EST) Received: from omta20.westchester.pa.mail.comcast.net ([76.96.62.71]) by qmta05.westchester.pa.mail.comcast.net with comcast id 7pPi1g0071YDfWL55q58K4; Mon, 14 Feb 2011 14:05:08 +0000 Received: from [192.168.1.100] ([24.3.224.125]) by omta20.westchester.pa.mail.comcast.net with comcast id 7q551g0152ix0EG3gq56E0; Mon, 14 Feb 2011 14:05:07 +0000 Message-ID: <4D59358E.2090206@gentoo.org> Date: Mon, 14 Feb 2011 09:00:46 -0500 From: Joseph Jezak User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101227 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: Rick Thomas Subject: Re: Rewrite of ofpath References: <4C922058.3080406@gentoo.org> <4C923A51.4080903@redhat.com> <4D58B7D1.7000800@gentoo.org> In-Reply-To: Cc: yaboot-devel@lists.ozlabs.org X-BeenThere: yaboot-devel@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Technical and development discussion regarding yaboot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org On 02/14/11 01:23, Rick Thomas wrote: > Hi Joseph! > > I've only looked at your patch, not given it a thorough test yet. But > I've got a couple of questions... > > 1) It looks like you set REAL_DEV and then immediately re-set it to a > different value. > > 2) I think your code to set CONTROLLER_PATH can't possibly work. > There is file called "devspec" on my newworld Mac where you seem to be > looking. > > Can you send me a copy of the fully-patched code? I'm not familiar > enough with git to get it myself. > > Thanks! > > Rick > 1) Whoops, you're absolutely right about REAL_DEV, I copy and pasted the code from the last version and forgot to use REAL_DEV throughout the new code so it wouldn't conflict with the DEVICE variable in the old code. This is fixed in the attached patch. 2) I'm not sure why you think CONTROLLER_PATH can't work, can you be more specific? It's trying to read the devspec file. It does work on my PB G4. I'll send a patched copy of ofpath to you in a following email. -Joe From e56e8b6873b71705452405a6bf4c180941439e0c Mon Sep 17 00:00:00 2001 From: Joseph Jezak josejx@gentoo.org Date: Mon, 14 Feb 2011 09:02:02 -0500 Subject: Update ofpath for libata devices. Signed-off-by: Joseph Jezak josejx@gentoo.org --- ybin/ofpath | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 95 insertions(+), 8 deletions(-) diff --git a/ybin/ofpath b/ybin/ofpath index aff5583..445b7e2 100755 --- a/ybin/ofpath +++ b/ybin/ofpath @@ -329,10 +329,86 @@ scsi_ofpath() ;; *) echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported" - return 1 + echo "" ;; esac - return 0 + echo "" +} + +### If scsi_ofpath can't find anything, try a new method +scsi_sys_ofpath() { + ### Get the sysfs mount point + local SYS="$(m=`grep '.* .* sysfs ' /proc/mounts | head -n 1` ; echo `d=${m#* };echo ${d%% *}`)"; + if [ -z "$SYS" -o ! -d "$SYS" ] ; then + echo 1>&2 "$PRG: Unable to determine sysfs mountpoint"; + echo ""; + return; + fi + + ### Get the device name and dereference it to support devices like /dev/cdrom1 + local REAL_DEV=$(readlink -f "$DEVICE") + REAL_DEV=$(basename "$REAL_DEV") + if [ "$REAL_DEV" == "" ] || [ ! -e "/dev/$REAL_DEV" ]; then + echo 1>&2 "ofpath: Invalid device: /dev/$REAL_DEV"; + echo ""; + return; + fi + + ### Get the partition if it exists + case ${REAL_DEV} in + sd*) PARTITION="${REAL_DEV#sd?}" ;; + ### No partition for sr/sg devices + sr*) PARTITION="${REAL_DEV#sr?}" ;; + sg*) PARTITION="${REAL_DEV#sg?}" ;; + *) echo 1>&2 "ofpath: Unknown device string."; return "";; + esac + + ### Get the disk device name + DISK_NAME="${REAL_DEV%%${PARTITION}}"; + + ### Find the devspec for the controller + DEVSPEC=$(cd -P "$SYS/block/${DISK_NAME}/device" && pwd) + if [ "${DEVSPEC}" == "" ]; then + echo 1>&2 "ofpath: Unable to determine device path!"; + echo ""; + return; + fi + + ### Get the OF Path of the controller + CONTROLLER_PATH=$(cat "${DEVSPEC}/../../../devspec"); + if [ "$CONTROLLER_PATH" == "" ]; then + echo 1>&2 "ofpath: Unable to find the controller path!"; + echo ""; + return; + fi + + ### Generate the disk number and partition info + DISK_NO="$(cd ${DEVSPEC}/../; pwd)"; + DISK_NO="${DISK_NO##*:}"; + DISK_NO="disk@${DISK_NO}:"; + + ### We need to get the controller port path if it has one + if [ ! -d "/proc/device-tree/$CONTROLLER_PATH/disk" ] && [ ! -d "/proc/device-tree/$CONTROLLER_PATH/$DISK_NO" ]; then + ### FIXME Does every scsi device uses the host nomenclature? + PORT="$(cd ${DEVSPEC}/../../; pwd)"; + PORT="${PORT##*host}"; + CTL_PORT="${CONTROLLER_PATH##*/}"; + CTL_PORT="${CTL_PORT%%-root*}"; + PORT="$CTL_PORT@$PORT"; + fi + + ### Add the partition information if required + if [ ! $PARTITION == "" ]; then + DISK_NO="${DISK_NO}${PARTITION}"; + fi + + ### Build the OF Path and print it out + if [ "$PORT" == "" ]; then + echo "$CONTROLLER_PATH/$DISK_NO"; + else + echo "$CONTROLLER_PATH/$PORT/$DISK_NO"; + fi + return; } ide_ofpath() @@ -451,14 +527,25 @@ ide_ofpath() ## sd* scsi disks , hd* ide disks. newworld() { + local SCSI_PATH="" case "$DEVNODE" in - sd*) - ## use common scsiinfo function to get info we need. - scsiinfo || return 1 + sd*|sr*|sg*) + ### Run the new sysfs version, this version will get libata results + SCSI_PATH=`scsi_sys_ofpath` + + ### Check if we got a result from the last call and if not, run the old code + if [ "${SCSI_PATH}" == "" ]; then + ## use common scsiinfo function to get info we need. + scsiinfo || return 1 + + ## now we have the data for /@$DEVID:$PARTITION + ## find the actual OF path. + SCSI_PATH=`scsi_ofpath` + fi + + ### Echo the found path + echo ${SCSI_PATH} - ## now we have the data for /@$DEVID:$PARTITION - ## find the actual OF path. - scsi_ofpath || return 1 ;; hd*) ide_ofpath || return 1