diff mbox

Rewrite of ofpath

Message ID 4D58B7D1.7000800@gentoo.org
State Superseded
Headers show

Commit Message

Joseph Jezak Feb. 14, 2011, 5:04 a.m. UTC
On 09/16/10 11:40, Roman Rakus wrote:
> At first, thanks for the interest and for "patch".
> I will take a deeper look later, so now just only a few notes:
> Better will be to send git commits (by `git format-patch' and `git
> send-email')
> Better is to use `printf' instead of `echo'
> From the code:
>
> ### Set this to 1 to turn on debugging messages
> DEBUG=0
>
>
> I will not set DEBUG variable here. So we can use `DEBUG=1 ofpath ...'
> call.
>
> Anyway, it needs deeper investigation.
>
> RR
> _______________________________________________
> Yaboot-devel mailing list
> Yaboot-devel@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/yaboot-devel
>
Since I haven't heard back, I adapted my code to the original ofpath
after some concern from the Debian project that I had gotten rid of
legacy code. Here is the patch that implements this against the current
git head.
From 3e2f4c19c2c0d5af785ab904395ff58d9ba7104e Mon Sep 17 00:00:00 2001
From: Joseph Jezak josejx@gentoo.org <Joseph Jezak josejx@gentoo.org>
Date: Sun, 13 Feb 2011 23:38:36 -0500
Subject: Update ofpath for libata devices.


Signed-off-by: Joseph Jezak josejx@gentoo.org <Joseph Jezak josejx@gentoo.org>
---
 ybin/ofpath |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 95 insertions(+), 8 deletions(-)

Comments

Rick Thomas Feb. 14, 2011, 6:23 a.m. UTC | #1
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


On Feb 14, 2011, at 12:04 AM, Joseph Jezak wrote:

> On 09/16/10 11:40, Roman Rakus wrote:
>> At first, thanks for the interest and for "patch".
>> I will take a deeper look later, so now just only a few notes:
>> Better will be to send git commits (by `git format-patch' and `git
>> send-email')
>> Better is to use `printf' instead of `echo'
>> From the code:
>>
>> ### Set this to 1 to turn on debugging messages
>> DEBUG=0
>>
>>
>> I will not set DEBUG variable here. So we can use `DEBUG=1  
>> ofpath ...'
>> call.
>>
>> Anyway, it needs deeper investigation.
>>
>> RR
>> _______________________________________________
>> Yaboot-devel mailing list
>> Yaboot-devel@lists.ozlabs.org
>> https://lists.ozlabs.org/listinfo/yaboot-devel
>>
> Since I haven't heard back, I adapted my code to the original ofpath
> after some concern from the Debian project that I had gotten rid of
> legacy code. Here is the patch that implements this against the  
> current
> git head.
>
> <ofpath.patch>_______________________________________________
> Yaboot-devel mailing list
> Yaboot-devel@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/yaboot-devel
Tony Breeds Oct. 19, 2011, 12:55 a.m. UTC | #2
On Mon, Feb 14, 2011 at 12:04:17AM -0500, Joseph Jezak wrote:

> Since I haven't heard back, I adapted my code to the original ofpath
> after some concern from the Debian project that I had gotten rid of
> legacy code. Here is the patch that implements this against the current
> git head.

I like this approch, however it fails on the IBM pSeries machines I
tested it on.  I'll try to nail down why it fails and post a devel
version of ofpath for people to bang on.

Tony.
acrux Oct. 20, 2011, 8:46 p.m. UTC | #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 19 Oct 2011 11:55:11 +1100
Tony Breeds <tony@bakeyournoodle.com> wrote:

> On Mon, Feb 14, 2011 at 12:04:17AM -0500, Joseph Jezak wrote:
> 
> > Since I haven't heard back, I adapted my code to the original ofpath
> > after some concern from the Debian project that I had gotten rid of
> > legacy code. Here is the patch that implements this against the
> > current git head.
> 
> I like this approch, however it fails on the IBM pSeries machines I
> tested it on.  I'll try to nail down why it fails and post a devel
> version of ofpath for people to bang on.
> 
> Tony.

ofpathname is a script available in powerpc-utils from IBM [1] and it
seems to work fine with modern kernels on pseries.

[1] http://sourceforge.net/projects/powerpc-utils/files/powerpc-utils/

cheers,
- --nico
- -- 
GNU/Linux on Power Architecture
CRUX PPC - http://cruxppc.org/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEARECAAYFAk6giKYACgkQxq34tDeO7LhjQQCfZV9yZKNIXRFQcbLVuAwYLGmE
JRkAn3QQIMQSefuyBIwAAzCCGujKbpWZ
=Afjp
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/ybin/ofpath b/ybin/ofpath
index aff5583..2e0fad8 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 "$DEVICE")
+	if [ "$DEVICE" == "" ] || [ ! -e "/dev/$DEVICE" ]; then
+		echo 1>&2 "ofpath: Invalid device: /dev/$DEVICE";
+		echo "";
+		return;
+	fi
+
+	### Get the partition if it exists
+	case ${REAL_DEV} in
+		sd*) PARTITION="${DEVICE#sd?}" ;;
+		### No partition for sr/sg devices
+		sr*) PARTITION="${DEVICE#sr?}" ;;
+		sg*) PARTITION="${DEVICE#sg?}" ;;
+		*) echo 1>&2 "ofpath: Unknown device string."; return "";;
+	esac
+
+	### Get the disk device name
+	DISK_NAME="${DEVICE%%${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