File: setupDisk

package info (click to toggle)
zvmcloudconnector 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,092 kB
  • sloc: ansic: 45,973; python: 29,045; sh: 2,732; makefile: 790
file content (592 lines) | stat: -rwxr-xr-x 21,273 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#!/bin/bash
###############################################################################
# Copyright 2017 IBM Corp.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
###############################################################################
# This script is used to handle xCAT disk initialization and configuration(eg.
# attach/detach a SCSI volume, add an additional ephemeral disk when vm is in
# inactive status). It will be invoked and executed when vm start up.
###############################################################################
version=3.0

function getOsVersion {
  # @Description:
  #   Returns the Linux distro version in an easy to parse format.
  # @Input:
  #   None
  # @Output:
  #   os - Variable set with OS and version information.  For example:
  #        "rhel62" or "sles11sp2"
  # @Code:
  if [[ -e "/etc/os-release" ]]; then
    os=`cat /etc/os-release | grep "^ID=" | sed \
      -e 's/ID=//' \
      -e 's/"//g'`
    version=`cat /etc/os-release | grep "^VERSION_ID=" | sed \
      -e 's/VERSION_ID=//' \
      -e 's/"//g' \
      -e 's/\.//'`
    os=$os$version

  #The /etc/SuSE-release file will be deprecated in sles11.4 and later release
  elif [[ -e "/etc/SuSE-release" ]]; then
    os='sles'
    version=`cat /etc/SuSE-release | grep "VERSION =" | sed \
      -e 's/^.*VERSION =//' \
      -e 's/\s*$//' \
      -e 's/.//' \
      -e 's/[^0-9]*([0-9]+).*/$1/'`
    os=$os$version

    # Append service level
    level=`echo "/etc/SuSE-release" | grep "LEVEL =" | sed \
      -e 's/^.*LEVEL =//' \
      -e 's/\s*$//' \
      -e 's/.//' \
      -e 's/[^0-9]*([0-9]+).*/$1/'`
    os=$os'sp'$level

  #The /etc/redhat-release file will be deprecated in rhel7 and later release
  elif [[ -e "/etc/redhat-release" ]]; then
    os='rhel'
    version=`cat /etc/redhat-release | grep -i "Red Hat Enterprise Linux Server" | sed \
      -e 's/[A-Za-z\/\.\(\)]//g' \
      -e 's/^ *//g' \
      -e 's/ *$//g' \
      -e 's/\s.*$//'`
    os=$os$version
  fi
  return
}

function onlineDevice {
  # @Description:
  #   Brings a Linux device online.
  # @Input:
  #   Device number, e.g. "0.0.000c"
  # @Output:
  #   Return code indicates success or failure
  # @Code:
  device=$1
  local funcName="onlineDevice"
  rc=$(/sbin/chccwdev -e $device > /dev/null; echo $?)
  if (( rc != 0 )); then
    if [[ -e /sbin/cio_ignore ]]; then
      rc=$(/sbin/cio_ignore -r 0.0.$device > /dev/null; echo $?)
      which udevadm &> /dev/null && udevadm settle || udevsettle
    fi
    rc=$(/sbin/chccwdev -e $device > /dev/null; echo $?)
    if (( rc != 0 )); then
      echo "$funcName (Error) Could not activate the virtual device $device"
      return 1
    fi
  fi
  which udevadm &> /dev/null && udevadm settle || udevsettle
  return 0
}

function setupDisk {
  # @Description:
  #   Processes a disk file for the following functions:
  #     Create a file system node
  #     Remove a file system node
  #     Setup a SCSI volume
  #     Removes a SCSI volume
  #     Add a mdisk based ephemeral disk
  # @Input:
  #   Disk handling parameters
  # @Output:
  #   None
  # @Code:
  local funcName="setupDisk"

  # Parse the parameter from parameter list
  for parameter in $@; do
    keyName=${parameter%\=*}
    value=${parameter#*\=}
    value=$(echo ${value} | sed -e 's/^ *//g')
    newKey='xcat_'$keyName
    eval $newKey=$value
  done

  # Remove the invokeScript.sh file after we have read it
  rm -f invokeScript.sh

  ##########################################################################
  # Handle creating a file system node
  # Disk handler input parameters:
  #   action - "createfilesysnode"
  #   srcFile - location/name of the source file for the mknod command
  #   xcat_tgtFile - location/name of the target file for the mknod command
  ##########################################################################
  if [[ $xcat_action == "createfilesysnode" ]]; then
    echo "Creating a file system node, source: $xcat_srcFile, target: $xcat_tgtFile"

    if [[ ! -n $xcat_srcFile ]]; then
      echo "$funcName (Error) Source file for creating a file system node was not specified"
      return
    fi

    if [[ ! -n $xcat_tgtFile ]]; then
      echo "$funcName (Error) Target file for creating a file system node was not specified"
      return
    fi
    if [[ -e $xcat_tgtFile ]]; then
      echo "$funcName (Error) Target file for creating a file system node already exists"
      return
    fi

    configFile='/etc/udev/rules.d/56-zfcp.rules'
    # Create udev config file if not exist
    if [[ ! -e $configFile ]]; then
      touch $configFile
      if [[ $os == rhel* ]]; then
        echo "KERNEL==\"zfcp\", RUN+=\"/sbin/zfcpconf.sh\"" >> ${configFile}
        echo "KERNEL==\"zfcp\", RUN+=\"/sbin/multipath -r\"" >> ${configFile}
      fi
    fi

    tgtNode=$(echo ${xcat_tgtFile} | sed -e 's/^\/dev\///')
    if [[ $os == sles* || $os == rhel* ]]; then
      wwpn_lun=$(echo ${xcat_srcFile} | sed -e 's/^\/dev.*-zfcp-//')
      wwpn=$(echo ${wwpn_lun} | sed -e 's/:0x.*//')
      lun=$(echo ${wwpn_lun} | sed -e 's/^0x.*://')
    else
      wwpn_lun=$(echo ${xcat_srcFile} | sed -e 's/^\/dev.*-fc-//')
      wwpn=$(echo ${wwpn_lun} | sed -e 's/-lun-.*//')
      lun=$(echo ${wwpn_lun} | sed -e 's/^0x.*-lun-//')
    fi


    multipath=0
    out=`echo $wwpn | grep ","`
    if [[ -n "$out" ]]; then
      multipath=1
    fi

    if [[ $os == sles* || $os == rhel* ]]; then
      fcp=$(echo ${xcat_srcFile} | sed -e 's/^\/dev.*ccw-0.0.//' | sed -e 's/-zfcp-.*$//')
    else
      fcp=$(echo ${xcat_srcFile} | sed -e 's/^\/dev.*ccw-0.0.//' | sed -e 's/-fc-.*$//')
    fi
    oldIFS=$IFS
    IFS=","
    fcpList=($fcp)
    for fcp in ${fcpList[@]}
    do
      if [[ $multipath == 1 ]]; then
        # Find the name of the multipath device by arbitrary one path in the set
        wwpnList=($wwpn)
        for wwpn in ${wwpnList[@]}
        do
          if [[ ${wwpn:0:2} -ne "0x" ]]; then
            wwpn="0x$wwpn"
          fi
          if [[ $os == sles* || $os == rhel* ]]; then
            cur_wwpn_lun=${wwpn}:${lun}
            srcFile=$(echo ${xcat_srcFile} | sed -e 's/-zfcp-.*//')"-zfcp-"$cur_wwpn_lun
            srcFile=$(echo ${srcFile} | sed -e 's/ccw-.*-zfcp/ccw-0.0.'$fcp'-zfcp/')
          else
            cur_wwpn_lun=${wwpn}-lun-${lun}
            srcFile=$(echo ${xcat_srcFile} | sed -e 's/-fc-.*//')"-fc-"$cur_wwpn_lun
            srcFile=$(echo ${srcFile} | sed -e 's/ccw-.*-fc/ccw-0.0.'$fcp'-fc/')
          fi

          out=`/usr/bin/stat --printf=%n ${srcFile}`
          if (( $? != 0 )); then
            echo "$funcName (Error) Unable to stat the source file: $srcFile"
            continue
          fi

          out=`/sbin/udevadm info --query=all --name=$srcFile | grep ID_SERIAL=`
          devName=$(echo ${out} | sed -e 's/^E:\s//')
          multipathUuid=$(echo $devName | sed -e 's/ID_SERIAL=//')
          if [[ -n "$multipathUuid" ]]; then
            break
          fi
        done

        if [[ -z "$multipathUuid" ]]; then
            echo "$funcName (Error) Building up multipath failed!"
            return
        fi
      else
        if [[ $os == sles* || $os == rhel* ]]; then
          srcFile=$(echo ${xcat_srcFile} | sed -e 's/ccw-.*-zfcp/ccw-0.0.'$fcp'-zfcp/')
        else
          srcFile=$(echo ${xcat_srcFile} | sed -e 's/ccw-.*-zfcp/ccw-0.0.'$fcp'-fc/')
        fi
        out=`/usr/bin/stat --printf=%n ${srcFile}`
        if (( $? != 0 )); then
          echo "$funcName (Error) Unable to stat the source file: $xcat_srcFile"
          return
        fi
      fi
    done
    IFS=$oldIFS

    # Add the entry into udev config file
    if [[ $multipath == 1 ]]; then
      echo "KERNEL==\"dm*\", ENV{DM_UUID}==\"mpath-${multipathUuid}\", SYMLINK+=\"${tgtNode}\"" >> ${configFile}
      udevadm control --reload
      udevadm trigger --sysname-match=dm-*
    else
      echo "KERNEL==\"sd*\", ATTRS{wwpn}==\"${wwpn}\", ATTRS{fcp_lun}==\"${lun}\", SYMLINK+=\"${tgtNode}%n\"" >> ${configFile}
      udevadm control --reload
      udevadm trigger --sysname-match=sd*
    fi

  echo "$funcName successfully create the file system node ${xcat_tgtFile}"

  ##########################################################################
  # Handle removing a file system node
  # Disk file input parameters:
  #   action - "removefilesysnode"
  #   tgtFile - location/name of the target file for the mknod command
  ##########################################################################
  elif [[ $xcat_action == "removefilesysnode" ]]; then
    echo "Removing a file system node, target: $xcat_tgtFile"
    if [[ ! -n $xcat_tgtFile ]]; then
      echo "$funcName (Error) Target file for creating a file system node was not specified"
      return
    fi

    configFile='/etc/udev/rules.d/56-zfcp.rules'
    tgtNode=$(echo ${xcat_tgtFile} | sed -e 's/^\/dev\///')

    sed -i -e /SYMLINK+=\"${tgtNode}%n\"/d ${configFile}
    sed -i -e /SYMLINK+=\"${tgtNode}\"/d ${configFile}
    udevadm control --reload
    udevadm trigger --sysname-match=sd*
    udevadm trigger --sysname-match=dm-*
    echo "$funcName successfully remove the file system node ${xcat_tgtFile}"

  ##########################################################################
  # Handle adding a SCSI volume
  # Disk file input parameters:
  #   action - "addScsiVolume"
  #   fcpAddr - FCP device address
  #   wwpn - WWPN number
  #   lun - LUN number
  ##########################################################################
  elif [[ $xcat_action == "addScsiVolume" ]]; then
    echo "Adding a SCSI Volume, FCP addr: $xcat_fcpAddr, WWPN: $xcat_wwpn, LUN: $xcat_lun"

    # Validate the input
    if [[ ! -n $xcat_fcpAddr ]]; then
      echo "$funcName (Error) FCP address was not specified"
      return
    fi
    xcat_fcpAddr=`echo $xcat_fcpAddr | tr '[A-Z]' '[a-z]'`

    if [[ ! -n $xcat_wwpn ]]; then
      echo "$funcName (Error) WWPN was not specified"
      return
    fi
    xcat_wwpn=`echo $xcat_wwpn | tr '[A-Z]' '[a-z]'`

    if [[ ! -n $xcat_lun ]]; then
      echo "$funcName (Error) LUN was not specified"
      return
    fi
    xcat_lun=`echo $xcat_lun | tr '[A-Z]' '[a-z]'`
    decimal_lun=$((16#${xcat_lun:0:4}))

    # Online the device
    oldIFS=$IFS
    IFS=","
    fcp_list=($xcat_fcpAddr)
    for fcp in ${fcp_list[@]}
    do
      rc= onlineDevice $fcp
      if (( rc != 0 )); then
        return
      fi
      if [[ $os == sles12* ]]; then
        out=`cat /boot/zipl/active_devices.txt | grep -i "0.0.$fcp"`
        if [[ -z $out ]]; then
          /sbin/zfcp_host_configure 0.0.$fcp 1
        fi
      elif [[ $os == sles11* ]]; then
        /sbin/zfcp_host_configure 0.0.$fcp 1
      elif [[ $os == ubuntu* ]]; then
        /sbin/chzdev zfcp-host $fcp -e
      fi
    done

    multipath=0
    out=`echo $xcat_wwpn | grep ","`
    if [[ -n "$out" ]]; then
      multipath=1
    fi

    # Start multipathd service
    if [[ $multipath == 1 ]]; then
        if [[ $os == sles* ]]; then
            insserv multipathd
        elif [[ $os == rhel6* ]]; then
            chkconfig multipathd on
        else
            systemctl enable multipathd
        fi
        modprobe dm-multipath
    fi

    for fcp in ${fcp_list[@]}
    do
      wwpn_list=($xcat_wwpn)
      for wwpn in ${wwpn_list[@]}
      do
        # Set WWPN and LUN in sysfs
        echo 0x$xcat_lun > /sys/bus/ccw/drivers/zfcp/0.0.$fcp/0x$wwpn/unit_add

        # Set WWPN and LUN in configuration files
        if [[ $os == sles* ]]; then
          #   SLES: /etc/udev/rules.d/51-zfcp*
          /sbin/zfcp_disk_configure 0.0.$fcp $wwpn $xcat_lun 1

          # Configure zFCP device to be persistent
          touch /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules

          # Check if the file already contains the zFCP channel
          out=`cat "/etc/udev/rules.d/51-zfcp-0.0.$fcp.rules" | egrep -i "ccw/0.0.$fcp]online"`
          if [[ ! $out ]]; then
            echo "ACTION==\"add\", SUBSYSTEM==\"ccw\", KERNEL==\"0.0.$fcp\", IMPORT{program}=\"collect 0.0.$fcp %k 0.0.$fcp zfcp\"" \
              | tee -a /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules
            echo "ACTION==\"add\", SUBSYSTEM==\"drivers\", KERNEL==\"zfcp\", IMPORT{program}=\"collect 0.0.$fcp %k 0.0.$fcp zfcp\"" \
              | tee -a /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules
            echo "ACTION==\"add\", ENV{COLLECT_0.0.$fcp}==\"0\", ATTR{[ccw/0.0.$fcp]online}=\"1\"" \
              | tee -a /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules
          fi

          echo "ACTION==\"add\", KERNEL==\"rport-*\", ATTR{port_name}==\"0x$wwpn\", SUBSYSTEMS==\"ccw\", KERNELS==\"0.0.$fcp\", ATTR{[ccw/0.0.$fcp]0x$wwpn/unit_add}=\"0x$xcat_lun\"" \
            | tee -a /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules
        elif [[ $os == rhel* ]]; then
          #   RHEL: /etc/zfcp.conf
          echo "0.0.$fcp 0x$wwpn 0x$xcat_lun" >> /etc/zfcp.conf
          echo "add" > /sys/bus/ccw/devices/0.0.$fcp/uevent
        elif [[ $os == ubuntu* ]]; then
          #   Ubuntu: chzdev zfcp-lun 0.0.$device:0x$wwpn:0x$lun -e
          /sbin/chzdev zfcp-lun 0.0.$fcp:0x$wwpn:0x$xcat_lun -e
        fi

        # Settle the file system so when we are done the device is fully available
        if [[ $(which udevadm 2> /dev/null) != '' ]]; then
          udevadm settle
        else
          udevsettle
        fi
        if [[ $os == rhel* || $os == sles* ]]; then
          if [[ ! -e "/dev/disk/by-path/ccw-0.0.${fcp}-zfcp-0x${wwpn}:0x${xcat_lun}" ]]; then
            # Sometimes the file takes longer to appear.  We will wait up to 3 minutes.
            maxTime=0
            for time in 1 2 2 5 10 10 30 60 60
            do
              if [[ -e "/dev/disk/by-path/ccw-0.0.${fcp}-zfcp-0x${wwpn}:0x${xcat_lun}" ]]; then
                # Leave the loop now that the file exists
                break
              fi
              maxTime=$maxTime+$time
              echo "Sleeping for $time seconds to allow /dev/disk/by-path/ccw-0.0.${fcp}-zfcp-0x${wwpn}:0x${xcat_lun} to be created"
              sleep $time
            done
          fi
          if [[ ! -e "/dev/disk/by-path/ccw-0.0.${fcp}-zfcp-0x${wwpn}:0x${xcat_lun}" ]]; then
            echo "/dev/disk/by-path/ccw-0.0.${fcp}-zfcp-0x${wwpn}:0x${xcat_lun} did not appear in $maxTime seconds, continuing."
          fi
        elif [[ $os == ubuntu* ]]; then
          if [[ ! -e "/dev/disk/by-path/ccw-0.0.${fcp}-fc-0x${wwpn}-lun-${decimal_lun}" ]]; then
            # Sometimes the file takes longer to appear.  We will wait up to 3 minutes.
            maxTime=0
            for time in 1 2 2 5 10 10 30 60 60
            do
              if [[ -e "/dev/disk/by-path/ccw-0.0.${fcp}-fc-0x${wwpn}-lun-${decimal_lun}" ]]; then
                # Leave the loop now that the file exists
                break
              fi
              maxTime=$maxTime+$time
              echo "Sleeping for $time seconds to allow /dev/disk/by-path/ccw-0.0.${fcp}-fc-0x${wwpn}-lun-${decimal_lun} to be created"
              sleep $time
            done
          fi
          if [[ ! -e "/dev/disk/by-path/ccw-0.0.${fcp}-fc-0x${wwpn}-lun-${decimal_lun}" ]]; then
            echo "/dev/disk/by-path/ccw-0.0.${fcp}-fc-0x${wwpn}-lun-${decimal_lun} did not appear in $maxTime seconds, continuing."
          fi
        fi
      done
    done
    IFS=$oldIFS

    /sbin/multipath -r

  echo "$funcName successfully create the SCSI volume"


  ##########################################################################
  # Handle removing a SCSI volume
  # Disk file input parameters:
  #   action - "removeScsiVolume"
  #   fcpAddr - FCP device address
  #   wwpn - WWPN number
  #   lun - LUN number
  ##########################################################################
  elif [[ $xcat_action == "removeScsiVolume" ]]; then
    echo "Removing a SCSI Volume, FCP addr: $xcat_fcpAddr, WWPN: $xcat_wwpn, LUN: $xcat_lun"

    # Validate the input
    if [[ ! -n $xcat_fcpAddr ]]; then
      echo "$funcName (Error) FCP address was not specified"
      return
    fi
    xcat_fcpAddr=`echo $xcat_fcpAddr | tr '[A-Z]' '[a-z]'`

    if [[ ! -n $xcat_wwpn ]]; then
      echo "$funcName (Error) WWPN was not specified"
      return
    fi
    xcat_wwpn=`echo $xcat_wwpn | tr '[A-Z]' '[a-z]'`

    if [[ ! -n $xcat_lun ]]; then
      echo "$funcName (Error) LUN was not specified"
      return
    fi
    xcat_lun=`echo $xcat_lun | tr '[A-Z]' '[a-z]'`

    oldIFS=$IFS
    IFS=","
    fcp_list=($xcat_fcpAddr)
    for fcp in ${fcp_list[@]}
    do
      wwpn_list=($xcat_wwpn)
      for wwpn in ${wwpn_list[@]}
      do
        # Delete the SCSI device
        scsiDevice=`lszfcp -l 0x$xcat_lun | grep 0x$wwpn | cut -d " " -f2`
        if [[ -n $scsiDevice ]]; then
          echo 1 > "/sys/bus/scsi/devices/$scsiDevice/delete"
        fi

        # Delete WWPN and LUN from sysfs
        if [[ -e /sys/bus/ccw/drivers/zfcp/0.0.$fcp/0x$wwpn/unit_remove ]]; then
          if [[ $(which udevadm 2> /dev/null) != '' ]]; then
            udevadm settle
          else
            udevsettle
          fi
          echo 0x$xcat_lun > /sys/bus/ccw/drivers/zfcp/0.0.$fcp/0x$wwpn/unit_remove
        fi

        # Delete WWPN and LUN from configuration files
        if [[ $os == sles11* || $os == sles12* ]]; then
          #   SLES: /etc/udev/rules.d/51-zfcp*
          expression="/$xcat_lun/d"
          sed --in-place -e $expression /etc/udev/rules.d/51-zfcp-0.0.$fcp.rules
        elif [[ $os == rhel* ]]; then
          #   RHEL: /etc/zfcp.conf
          expression="/$xcat_lun/d"
          sed --in-place -e $expression /etc/zfcp.conf
        elif [[ $os == ubuntu* ]]; then
          #   Ubuntu: chzdev zfcp-lun 0.0.$device:0x$wwpn:0x$lun -d
          /sbin/chzdev zfcp-lun 0.0.$fcp:0x$wwpn:0x$xcat_lun -d
        fi
      done
    done
    IFS=$oldIFS
    /sbin/multipath -W
    /sbin/multipath -r
    echo "$funcName successfully remove the SCSI volume"

  ###########################################################################
  # Handle adding a mdisk based ephemeral disk.
  # Disk file input parameters:
  #   action  - "addMdisk"
  #   vaddr   - virtual address of the minidisk
  #   filesys - Filesystem type
  #   mntdir - The directory that mount the mdisk to
  ##########################################################################
  elif [[ $xcat_action == "addMdisk" ]]; then
    echo "Adding a minidisk based ephemeral disk, Vaddr: $xcat_vaddr, Filesystem: $xcat_filesys mountpoint:$xcat_mntdir"

    # Validate the input
    if [[ ! -n $xcat_vaddr ]]; then
      echo "$funcName (Error) Virtual address was not specified"
      return
    fi
    xcat_vaddr=`echo $xcat_vaddr | tr '[A-Z]' '[a-z]'`

    # Online the device
    rc= onlineDevice $xcat_vaddr
    if (( rc != 0 )); then
      echo "$funcName (Error) fail to online the disk $xcat_vaddr"
      return
    fi

    # Configure the added dasd to be persistent
    echo "Permanently online the ephemeral disk"
    if [[ $os == rhel* ]]; then
      out=`cat "/etc/dasd.conf" | egrep -i $xcat_vaddr`
      if [[ ! $out ]]; then
        echo "0.0.$xcat_vaddr" >> /etc/dasd.conf
      fi
    elif [[ $os == sles* ]]; then
      /sbin/dasd_configure 0.0.$xcat_vaddr 1
    elif [[ $os == ubuntu16* ]]; then
      touch /etc/sysconfig/hardware/config-ccw-0.0.$xcat_vaddr
    else
      echo "$funcName (Error) failed to permanently online the disk:$xcat_vaddr on os: $os, please check if $os is in the supported distribution list"
      return
    fi


    # Mount the mdisk to the specified mount point
    echo "Mounting the ephemeral disk $xcat_vaddr to directory $xcat_mntdir"
    if [[ -d $xcat_mntdir ]]; then
      rm -rf $xcat_mntdir
    fi
    mkdir -p $xcat_mntdir

    cp /etc/fstab /etc/fstab.bak
    out=`cat "/etc/fstab" | egrep -i "ccw-0.0.$xcat_vaddr"`
    if [[  $out ]]; then
      sed -i '/ccw-0.0.'"$xcat_vaddr"'/d' /etc/fstab
    fi

    if [[ $os == sles12* ]]; then
      echo "/dev/disk/by-path/ccw-0.0.${xcat_vaddr}-part1 $xcat_mntdir $xcat_filesys defaults,nofail 0 0" >> /etc/fstab
    else
      echo "/dev/disk/by-path/ccw-0.0.${xcat_vaddr}-part1 $xcat_mntdir $xcat_filesys defaults 0 0" >> /etc/fstab
    fi

    out=`mount -a 2>&1`
    if [[ "$out" ]]; then
      echo "Fail to mount the disk $xcat_vaddr with reason $out"
      mv /etc/fstab.bak /etc/fstab
     mount -a
    else
      echo "The disk $xcat_vaddr has been mounted to $xcat_mntdir in format $xcat_filesys successfully"
    fi

  fi

  return
}

############################################################################
# Main Code Section
############################################################################
# Get Linux version
getOsVersion
setupDisk $@
rm -f setupDisk