Skip to content

Commit d0047ee

Browse files
author
Bart Sjerps
committed
Improve list option, add asm-menu
1 parent ea08530 commit d0047ee

File tree

5 files changed

+170
-108
lines changed

5 files changed

+170
-108
lines changed

asmdisks.spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: asmdisks
22
Summary: Replacement for Oracle ASMLib using UDEV
3-
Version: 1.4.6.0
3+
Version: 1.4.7.0
44
Release: 1%{?dtap}
55
BuildArch: noarch
66
License: GPLv3+
@@ -39,6 +39,7 @@ install -m 0755 -pt %{buildroot}/usr/bin bin/*
3939
/usr/share/man/man1/*
4040
%defattr(0755,root,root)
4141
/usr/bin/asm
42+
/usr/bin/asm-menu
4243
/usr/bin/asmstat
4344
/usr/bin/wipedisk
4445
/usr/bin/diskheader

src/CHANGELOG

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
* Wed Nov 12 Bart Sjerps <bart@outrun.nl> 1.4.5.2
2-
- Fix usage/no parameters
3-
4-
* Wed Nov 07 Bart Sjerps <bart@outrun.nl> 1.4.5.1
51
- List of changes to asm:
62

3+
2018-12-24 : Improve list option, add asm-menu
74
2018-11-23 : Overhaul: replace /sys/block/ parsing with lsblk, sanitize with shellcheck
85
2018-11-07 : Change rpmbuild process, added docs
96
2018-08-20 : Embedded manpage, removed DSSD support

src/README

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,4 @@
11
Release notes for asmdisks
2-
Author : Bart Sjerps
2+
Author: Bart Sjerps
33

4-
-------------------------------------------------------------------------------
5-
Updates
6-
=======
7-
2016-10-20 - 1.5
8-
- Added RHEL 7 support
9-
- Major script overhaul, removed some exotic bugs
10-
11-
2016-09-12 - 1.4
12-
13-
- Changed the package location to outrun-extras
14-
- Added EMC DSSD support
15-
- Fixed inconsistencies in the RPMbuild SPEC file
16-
17-
2016-06-28 - 1.3
18-
19-
- Fixed a minor error where UDEV complains during rewrite of the 99-asm.rules file.
20-
We now make a temporary file and overwrie the entire rules file at once to stop
21-
udev from complaining
22-
- Experimental EMC PowerPath support
23-
- Changed the PGP signature of the RPM package
24-
25-
2015-02-14 - 1.2-2 (minor update)
26-
27-
- Added TAB option (for scripting)
28-
29-
2014-11-06 - Update to 1.2
30-
31-
- Added import function - imports all unused disks that have an ASM disk label
32-
as vol01, vol02, ...
33-
- Added rename function and using -h or -? now works properly.
34-
35-
2014-10-24 - Update to 1.1
36-
37-
- Added bash-completion (if you have bash-completion installed)
38-
39-
If you enter "asm createdisk somevol [TAB]", bash will show /dev/sd[b-z] thru
40-
/dev/sdzz + all symlinks in /dev/mapper.
41-
"asm deletedisk [TAB]" shows all configured volumes.
42-
43-
- Copyright (GPLv3) notice added.
44-
45-
2014-06-24 - First version (1.0)
46-
47-
Bugfixes
48-
========
49-
50-
2014-10-27
51-
52-
- Bugfix for wipedisk and added -n option
53-
54-
2014-10-24
55-
56-
- deletedisk option with multiple slashes in volname failed
57-
- PATH=oracleasm:... now correctly sets non-standard owner/group
58-
for /dev/iorate/.. volumes
59-
60-
-------------------------------------------------------------------------------
61-
Known issues & workarounds
62-
==========================
63-
64-
- no support (yet) for EMC ScaleIO volumes. Planned for a future version.
4+
See CHANGELOG for a list of changes

src/bin/asm

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,29 @@ scandisks() {
269269
udevupdate
270270
}
271271

272+
devtype() {
273+
local dev id
274+
dev=/dev/"${1#*/dev/}"
275+
test -b "$dev" || return 0
276+
cmp -s <(dd if="$dev" bs=8k count=1 status=none) <(dd if=/dev/zero bs=8k count=1 status=none) \
277+
&& echo "blank" && return
278+
id=$(blkid -p -o udev "$dev" | awk -F= '/ID_PART_TABLE_TYPE/ || /ID_FS_TYPE/ {print $NF ; exit; }')
279+
case $id in
280+
dos|gpt|swap) echo "$id" ;;
281+
LVM2_member) echo "lvm" ;;
282+
linux_raid_member) echo "raid" ;;
283+
oracleasm) echo "asm" ;;
284+
xfs|ext3|ext4) echo "$id" ;;
285+
*) echo "unknown" ;;
286+
esac
287+
}
288+
272289

273290
# List functions
274291
printvol() {
275292
case $SEPARATOR in
276-
T) printf "%s\t%s\t%s\n" "$@" ;;
277-
*) printf "%-20s %11s %-20s\n" "$@" ;;
293+
T) printf "%s\t%s\t%s\t%s\n" "$@" ;;
294+
*) printf "%-20s %-11s %-8s %8s\n" "$@" ;;
278295
esac
279296
}
280297
printdisk() {
@@ -291,7 +308,6 @@ mpinfoprint() {
291308
esac
292309
}
293310

294-
295311
listvol() {
296312
local vol dev size
297313
local -i bytes
@@ -301,11 +317,11 @@ listvol() {
301317
read bytes < <(lsblk -nbdo size "$dev")
302318
read size < <(bc <<< "scale=1;$bytes/1073741824")
303319
fi
304-
printvol "${vol//oracleasm\//}" "${size:--}" "${dev:--}"
320+
printvol "${vol//oracleasm\//}" "${dev:--}" "$(devtype $dev)" "${size:--}"
305321
}
306322

307323
listvols() {
308-
test -z "$NOHEAD" && printvol Volume Size Devname
324+
test -z "$NOHEAD" && printvol Volume Device Type Size
309325
while IFS= read -r vol
310326
do
311327
listvol "$vol"
@@ -328,23 +344,7 @@ listdisk() {
328344
target=$(/sbin/powermt display dev="$dev" 2>/dev/null | awk -F= '/Pseudo name/ {print $2}') ;;
329345
*) return ;;
330346
esac
331-
if test -r /dev/"$dev" ; then
332-
if cmp -s <(dd if=/dev/"$dev" bs=8k count=1 status=none) <(dd if=/dev/zero bs=8k count=1 status=none); then
333-
disktype=blank
334-
else
335-
id=$(blkid -p -o udev /dev/"$dev" | awk -F= '/ID_PART_TABLE_TYPE/ || /ID_FS_TYPE/ {print $NF ; exit; }')
336-
case $id in
337-
dos|gpt|swap) disktype="$id" ;;
338-
LVM2_member) disktype="lvm" ;;
339-
linux_raid_member) disktype="raid" ;;
340-
oracleasm) disktype="asm" ;;
341-
xfs|ext3|ext4) disktype="$id" ;;
342-
*) disktype="unknown" ;;
343-
esac
344-
fi
345-
else
346-
disktype="?"
347-
fi
347+
disktype=$(devtype $dev)
348348
size=$(lsblk -ndo size /dev/"$dev")
349349
printdisk "/dev/$dev" "${scsi:-[-]}" "${size}" "${disktype:--}" "${target:--}"
350350
}
@@ -356,24 +356,11 @@ listdisks() {
356356
}
357357

358358
mpinfo() {
359-
local device=$1 dev size realpath fstype disktype mpvol
359+
local device=$1 dev size realpath disktype mpvol
360360
dev=$(dmsetup ls -o blkdevname | awk -v MP="$device" '$1==MP {print $2}'|tr -d '()')
361361
mpvol=$(multipath -ll -v 1 /dev/mapper/"$device")
362362
size=$(lsblk -ndo size /dev/"$dev")
363-
ptable=$(blkid -p -o udev /dev/"$dev" | awk -F= '$1=="ID_PART_TABLE_TYPE" {print $2}'|head -1)
364-
fstype=$(blkid -p -o udev /dev/"$dev" | awk -F= '$1=="ID_FS_TYPE" {print $2}'|head -1)
365-
if [ "$ptable" == "dos" ]; then disktype="dos"
366-
elif [ "$ptable" == "gpt" ]; then disktype="gpt"
367-
else
368-
case $fstype in
369-
LVM2_member) disktype="lvm" ;;
370-
linux_raid_member) disktype="raid" ;;
371-
oracleasm) disktype="asm" ;;
372-
xfs|ext*) disktype="$fstype" ;;
373-
"") disktype="blank" ;;
374-
*) disktype="unknown" ;;
375-
esac
376-
fi
363+
disktype=$(devtype "$dev")
377364
realpath=$(getlink "$dev")
378365
mpinfoprint "$dev" "[$mpvol]" "${size}" "${disktype:-blank}" "${realpath:--}"
379366
}
@@ -402,10 +389,10 @@ shift $((OPTIND - 1))
402389
ACTION=${1:-none}; shift
403390

404391
case $ACTION in
405-
none) listdisks ; exit $? ;;
406-
listdisks|disks) listdisks ; exit $? ;;
407-
list) listvols ; exit $? ;;
408-
dump) cat $rulesfile ; exit $? ;;
392+
none) listdisks ; exit $? ;;
393+
listdisks|disks) listdisks ; exit $? ;;
394+
list) listvols ; exit $? ;;
395+
dump) cat $rulesfile ; exit $? ;;
409396
esac
410397

411398
(($(id -u)==0)) || die "Run as root"

src/bin/asm-menu

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
#============================================================================
3+
# Title : menu-asm
4+
# Description : Menu frontend for ASMdisks
5+
# Author : Bart Sjerps <bart@outrun.nl>
6+
# License : GPLv3+
7+
# ---------------------------------------------------------------------------
8+
9+
set -u
10+
11+
die() { echo "$(basename $0): [die] $@" >&2 ; exit 10 ; }
12+
quit() { echo "$(basename $0): [quit] $@" ; exit 0 ; }
13+
msg() { echo "$(basename $0): [msg] $@" ; }
14+
err() { echo "$(basename $0): [err] $@" >&2 ; }
15+
16+
source /usr/lib/lightmenu.bash &>/dev/null || die "lightmenu not installed"
17+
18+
export BACKTITLE="ASMdisks menu on $(hostname)"
19+
20+
#============================================================================
21+
# Actions
22+
# ---------------------------------------------------------------------------
23+
24+
view_asmdisks() {
25+
messagebox -fresize --margin 2 --height2 0 --hline "Use \Z1PgUP PgDOWN\Zn to scroll" \
26+
--title "ASM disks" "$(asm -t disks | expand -t 10,20,28)"
27+
}
28+
29+
view_asmlist() {
30+
messagebox --margin 5 -fresize --hline "Use \Z1PgUP PgDOWN\Zn to scroll" \
31+
--title "ASM list" "$(asm list | expand -t 10,20,30,40)"
32+
}
33+
34+
view_asmavailable() {
35+
messagebox --margin 5 -fresize --hline "Use \Z1PgUP PgDOWN\Zn to scroll" \
36+
--title "ASM candidates" "$(asm -t disks | awk '$5=="-" && $4 == "blank" {print $0}')"
37+
}
38+
39+
view_asmadd() {
40+
local -a volname disks
41+
local NAME=
42+
43+
for c in $(seq 1 100); do
44+
NAME=$(printf "vol%s" $c)
45+
if [ ! -b /dev/oracleasm/$NAME ] ; then break ; fi
46+
done
47+
append volname "Volume /dev/oracleasm/" "$NAME"
48+
49+
for line in $(asm -t disks | awk '$5=="-" && ( $4=="blank" || $4=="asm" ) {print $1","$4"-"$3}'); do
50+
append disks "${line%%,*}" "${line#*,}" DEVICE
51+
done
52+
result=$(ldialog formlist --height2 12 --formx 24 --title "Add ASM volume" --title2 "Select device" volname disks) || return $?
53+
54+
volname=$(awk -F'\t' 'NR==1 && NF==1 {print $1}' <<< "$result")
55+
devname=$(awk -F'\t' 'NR==2 && NF==2 {print $2}' <<< "$result")
56+
57+
runcommand asm createdisk $volname $devname
58+
}
59+
60+
# TBD: update lightmenu.bash first to do listform
61+
view_asmrename() {
62+
local vol desc
63+
local -a disks
64+
status="Be careful when deleting ASM volumes still in use!"
65+
66+
IFS=$'\n' ; for disk in $(asm -t list | asm -t list | awk -F'\t' '{print $1":"$2"-"$3"-"$4"G"}')
67+
do
68+
vol=$(echo $disk | cut -d: -f1)
69+
desc=$(echo $disk | cut -d: -f2- | tr '-' ' ')
70+
append disks "$vol" "$desc" VOLNAME
71+
done
72+
unset IFS
73+
result=$(ldialog list --title "Rename ASM volume" --status "$status" disks) || return $?
74+
# runcommand asm deletedisk $result
75+
}
76+
77+
view_asmdel() {
78+
local vol desc
79+
local -a disks
80+
status="Be careful when deleting ASM volumes still in use!"
81+
82+
IFS=$'\n' ; for disk in $(asm -t list | asm -t list | awk -F'\t' '{print $1":"$2"-"$3"-"$4"G"}')
83+
do
84+
vol=$(echo $disk | cut -d: -f1)
85+
desc=$(echo $disk | cut -d: -f2- | tr '-' ' ')
86+
append disks "$vol" "$desc" VOLNAME
87+
done
88+
unset IFS
89+
result=$(ldialog list --title "Delete ASM volume" --status "$status" disks) || return $?
90+
runcommand asm deletedisk $result
91+
}
92+
93+
view_asmwipe() {
94+
local -a disks
95+
local dev disklist d
96+
status="\Z1WARNING WARNING WARNING\Zn\n"
97+
status+="Wiping a disk may lead to data loss! Make sure the disk you wipe has no important data on it!"
98+
99+
disklist="$(asm -t disks)"
100+
101+
for line in $(ls -d /sys/block/sd* )
102+
do
103+
dev=/dev/${line##*/}
104+
# TBD: UPDATE for detected bootdisk
105+
[[ "$dev" == "/dev/sda" ]] && continue
106+
d=$(awk -F'\t' -v DEV=$dev '$1==DEV {print $2,$4,$3}' <<< "$disklist")
107+
append disks "${dev:-x}" "$d"
108+
done
109+
result=$(ldialog list --height2 6 --title "Wipe disk label" --title2 "\Z1Warning\Zn" --status "$status" disks)
110+
runcommand wipedisk -f $result
111+
}
112+
#============================================================================
113+
# Menus
114+
# ---------------------------------------------------------------------------
115+
storagemenu() {
116+
local -a items
117+
118+
[[ "$(scsi_id --whitelisted /dev/sda)" == "" ]] && SCSI=MISSING || SCSI=OK
119+
status="$(printf 'UUID: %s' $SCSI)"
120+
append items Disks "Show all disks" view_asmdisks
121+
append items Volumes "Show ASM volumes" view_asmlist
122+
append items Available "Show available disks" view_asmavailable
123+
append items Rescan "Rescan SCSI stack for new disks" runcommand asm rescan
124+
append items Add "Add volume" view_asmadd
125+
append items Delete "Delete volume" view_asmdel
126+
append items Import "Import ASM volumes" runcommand asm import
127+
append items Wipe "Wipe disk label" view_asmwipe
128+
129+
lightmenu --title "ASM Storage configuration" --cancel Quit items
130+
rc=$?
131+
case $rc in
132+
253) ;;
133+
*) return $rc ;;
134+
esac
135+
}
136+
137+
lightmenu storagemenu

0 commit comments

Comments
 (0)