Changeset 33f74f7


Ignore:
Timestamp:
09/09/13 20:21:27 (13 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
4f9718b, 559e01f
Parents:
284b216 (diff), 59f367e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of github.com:pcbsd/pcbsd

Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • src-sh/libsh/functions.sh

    r3d7cbf4 r26599e2  
    666666  fi 
    667667} 
     668 
     669# Run-command silently, only display / halt if command exits with non-0 
     670rc_halt_s() 
     671{ 
     672  CMD="$@" 
     673 
     674  if [ -z "${CMD}" ] ; then 
     675    exit_err "Error: missing argument in rc_halt()" 
     676  fi 
     677 
     678  TMPRCLOG=`mktemp /tmp/.rc_halt.XXXXXX` 
     679  ${CMD} >${TMPRCLOG} 2>${TMPRCLOG} 
     680  STATUS=$? 
     681  if [ ${STATUS} -ne 0 ] ; then 
     682    cat ${TMPRCLOG} 
     683    rm ${TMPRCLOG} 
     684    exit_err "Error ${STATUS}: ${CMD}" 
     685  fi 
     686  rm ${TMPRCLOG} 
     687} 
  • src-sh/lpreserver/backend/functions.sh

    r1996f85 r59f367e  
    376376} 
    377377 
    378 add_mirror_disk() { 
     378add_zpool_disk() { 
    379379   pool="$1" 
    380380   disk="$2" 
     381   disk="`echo $disk | sed 's|/dev/||g'`" 
    381382 
    382383   if [ -z "$pool" ] ; then 
     
    387388   if [ -z "$disk" ] ; then 
    388389      exit_err "No disk specified" 
     390      exit 0 
     391   fi 
     392 
     393   if [ ! -e "/dev/$disk" ] ; then 
     394      exit_err "No such device: $disk" 
    389395      exit 0 
    390396   fi 
     
    394400   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
    395401 
    396    # Make sure zpool isn't raid 
    397    zpool list -H -v ${pool} | grep -q "raid" 
    398    if [ $? -eq 0 ] ; then exit_err "Cannot mirror a raidz pool!" ; fi 
     402   # Cleanup the target disk 
     403   echo "Deleting all partitions on: $disk" 
     404   rc_nohalt "gpart destroy -F $disk" >/dev/null 2>/dev/null 
     405   rc_nohalt "dd if=/dev/zero of=/dev/${disk} bs=1m count=1" >/dev/null 2>/dev/null 
     406   rc_nohalt "dd if=/dev/zero of=/dev/${disk} bs=1m oseek=`diskinfo /dev/${disk} | awk '{print int($3 / (1024*1024)) - 4;}'`" >/dev/null 2>/dev/null 
    399407 
    400408   # Grab the first disk in the pool 
    401    mDisk=`zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | head -n 1` 
     409   mDisk=`zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | grep -v "^raidz" | head -n 1` 
     410 
     411   # Is this MBR or GPT? 
     412   echo $mDisk | grep -q 's[0-4][a-z]$' 
     413   if [ $? -eq 0 ] ; then 
     414      # MBR 
     415      type="MBR" 
     416      # Strip off the "a-z" 
     417      rDiskDev=`echo $mDisk | rev | cut -c 2- | rev` 
     418   else 
     419      # GPT 
     420      type="GPT" 
     421      # Strip off the "p[1-9]" 
     422      rDiskDev=`echo $mDisk | rev | cut -c 3- | rev` 
     423   fi 
     424 
     425   # Make sure this disk has a layout we can read 
     426   gpart show $rDiskDev >/dev/null 2>/dev/null 
     427   if [ $? -ne 0 ] ; then  
     428      exit_err "failed to get disk device layout $rDiskDev" 
     429   fi 
     430 
     431   # Get the size of "freebsd-zfs & freebsd-swap" 
     432   sSize=`gpart show ${rDiskDev} | grep freebsd-swap | cut -d "(" -f 2 | cut -d ")" -f 1` 
     433   zSize=`gpart show ${rDiskDev} | grep freebsd-zfs | cut -d "(" -f 2 | cut -d ")" -f 1` 
     434    
     435   echo "Creating new partitions on $disk" 
     436   if [ "$type" = "MBR" ] ; then 
     437      # Create the new MBR layout 
     438      rc_halt_s "gpart create -s MBR -f active $disk" 
     439      rc_halt_s "gpart add -a 4k -t freebsd $disk"       
     440      rc_halt_s "gpart set -a active -i 1 $disk" 
     441      rc_halt_s "gpart create -s BSD ${disk}s1" 
     442      rc_halt_s "gpart add -t freebsd-zfs -s $zSize ${disk}s1" 
     443      if [ -n "$sSize" ] ; then 
     444        rc_halt_s "gpart add -t freebsd-swap -s $sSize ${disk}s1" 
     445      fi 
     446      aDev="${disk}s1a" 
     447   else 
     448      # Creating a GPT disk 
     449      rc_halt_s "gpart create -s GPT $disk" 
     450      rc_halt_s "gpart add -b 34 -s 1M -t bios-boot $disk" 
     451      rc_halt_s "gpart add -t freebsd-zfs -s $zSize ${disk}" 
     452      if [ -n "$sSize" ] ; then 
     453        rc_halt_s "gpart add -t freebsd-swap -s $sSize ${disk}" 
     454      fi 
     455      aDev="${disk}p2" 
     456   fi 
    402457 
    403458   # Now we can insert the target disk 
    404    zpool attach $pool $mDisk $disk 
    405    if [ $? -ne 0 ] ; then 
    406       exit_err "Failed attaching $disk" 
    407    fi 
    408  
    409    echo "Added $disk to zpool $pool. Resilver will begin automatically." 
     459   echo "Attaching to zpool: $aDev" 
     460   rc_halt_s "zpool attach $pool $mDisk $aDev" 
     461 
     462   # Lastly we need to stamp GRUB 
     463   echo "Stamping GRUB on: $disk" 
     464   rc_halt_s "grub-install --force /dev/${disk}" 
     465 
     466   echo "Added $disk ($aDev) to zpool $pool. Resilver will begin automatically." 
    410467   exit 0 
    411468} 
    412469 
    413 list_mirror_disks() { 
     470list_zpool_disks() { 
    414471   pool="$1" 
    415472 
     
    423480   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
    424481 
    425    # Make sure zpool isn't raid 
    426    zpool list -H -v ${pool} | grep -q "raid" 
    427    if [ $? -eq 0 ] ; then exit_err "Pool: $pool is raidz!" ; fi 
    428  
    429    zpool list -H -v | grep -v "^$pool" | awk '{print $1}' | grep -v "^mirror" | tail +2 > /tmp/.mList.$$ 
    430  
    431    while read line 
    432    do 
    433       echo "$line" | grep -q -e "spare" -e "log" -e "cache" 
    434       if [ $? -eq 0 ] ; then break ; fi 
    435  
    436       echo "$line"   
    437    done < /tmp/.mList.$$ 
    438    rm /tmp/.mList.$$ 
    439 } 
    440  
    441 rem_mirror_disk() { 
     482   zpool list -H -v $pool 
     483} 
     484 
     485rem_zpool_disk() { 
    442486   pool="$1" 
    443487   disk="$2" 
     
    456500   zpool status $pool >/dev/null 2>/dev/null 
    457501   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
    458  
    459    # Make sure zpool isn't raid 
    460    zpool list -H -v ${pool} | grep -q "raid" 
    461    if [ $? -eq 0 ] ; then exit_err "Cannot remove disks from a raidz pool!" ; fi 
    462502 
    463503   zpool detach $pool $disk 
     
    468508   exit 0 
    469509} 
     510 
     511offline_zpool_disk() { 
     512   pool="$1" 
     513   disk="$2" 
     514 
     515   if [ -z "$pool" ] ; then 
     516      exit_err "No pool specified" 
     517      exit 0 
     518   fi 
     519 
     520   if [ -z "$disk" ] ; then 
     521      exit_err "No disk specified" 
     522      exit 0 
     523   fi 
     524 
     525   # Check if pool exists 
     526   zpool status $pool >/dev/null 2>/dev/null 
     527   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
     528 
     529   zpool offline $pool $disk 
     530   exit $? 
     531} 
     532 
     533online_zpool_disk() { 
     534   pool="$1" 
     535   disk="$2" 
     536 
     537   if [ -z "$pool" ] ; then 
     538      exit_err "No pool specified" 
     539      exit 0 
     540   fi 
     541 
     542   if [ -z "$disk" ] ; then 
     543      exit_err "No disk specified" 
     544      exit 0 
     545   fi 
     546 
     547   # Check if pool exists 
     548   zpool status $pool >/dev/null 2>/dev/null 
     549   if [ $? -ne 0 ] ; then exit_err "Invalid pool: $pool"; fi 
     550 
     551   zpool online $pool $disk 
     552   exit $? 
     553} 
  • src-sh/lpreserver/lpreserver

    r5d99101 r59f367e  
    4747   listsnap - List snapshots of a zpool/dataset 
    4848     mksnap - Create a ZFS snapshot of a zpool/dataset 
    49      mirror - Enable / Disable ZFS mirroring to a local drive 
    5049  replicate - Enable / Disable ZFS replication to a remote system 
    5150 revertsnap - Revert zpool/dataset to a snapshot 
     
    5352        set - Set lpreserver options 
    5453     status - List datasets, along with last snapshot / replication date  
     54      zpool - Mange a zpool by attaching / detaching disks 
    5555__EOF__ 
    5656}; 
    5757 
    58 help_mirror() 
    59 { 
    60  title 
    61  echo "Help mirror 
    62  
    63 Life-Preserver mirror sub-system 
    64  
    65 Mirroring uses ZFS to create a exact copy of your target disk to a new drive, 
    66 such as an external USB disk. When first started the mirror will take a while 
    67 to sync or "resilver". Once this is finished your new disk will be kept in sync 
    68 with the target disk automatically, and can be used as a fall-back disk if the 
    69 primary begins to fail.  
    70  
    71 Should your primary disk fail the mirrored disk can then be used to restore 
    72 the system via the restore option of the PC-BSD installation media.  
    73  
    74 *NOTES*  
    75  
    76 * Mirroring will only work with a non-raidz ZFS pool. If you are using 
    77 raidz you will need to manage disks through the "zpool" command.  
    78  
    79 * The mirror disk must be the same size or larger than the target disk 
     58help_zpool() 
     59{ 
     60 title 
     61 echo "Help zpool 
     62 
     63Life-Preserver zpool sub-system 
     64 
     65The 'zpool' sub-command allows you to attach / detach drives to a zpool,  
     66as well as get status and more.  
     67 
     68When a drive is first attached to a zpool, it will be re-formatted with 
     69a new gpart layout and made bootable with GRUB. For this reason the disk 
     70must be the same size, or larger, than the first array disk SWAP + ZFS 
     71partition size.  
    8072 
    8173Available Flags: 
    82         list - List mirror disks 
    83          add - Add a new mirror disk 
    84       remove - Remove a mirror disk 
    85  
    86 Add Options: 
    87  
    88         add <zpool> <new disk> 
     74        list - List zpool disks 
     75      attach - Attach a new zpool disk 
     76      detach - Remove a zpool disk 
     77     offline - Mark a disk as offline 
     78      online - Mark a disk as being online again 
     79 
     80Attach Options: 
     81 
     82        attach <zpool> <new disk> 
    8983 
    9084        Example 1:  
    9185 
    92         add tank1 /dev/da0 
    93  
    94         Will enable mirroring of the tank1 pool to /dev/da0 
    95  
    96 Remove Options: 
    97  
    98         remove <zpool> <disk> 
     86        attach tank1 /dev/da0 
     87 
     88        Attach the disk /dev/da0 to tank1 pool. The disk will be  
     89        auto-partioned with a SWAP / ZFS partition and made bootable. 
     90 
     91Detach Options: 
     92 
     93        detach <zpool> <disk> 
    9994         
    100         Remove a mirrored disk from the zpool 
    101  
    102         Use 'mirror list' for a list of available disks  
     95        Detach a disk from the zpool 
     96 
     97        Use 'zpool list' for a list of available disks  
     98 
     99Offline Options: 
     100 
     101        offline <zpool> <disk>   
     102         
     103        Mark a disk in the zpool array as 'offline', should be when you 
     104        want to unplug a device, and anticipate plugging it back in later. 
     105 
     106Online Options: 
     107 
     108        online <zpool> <disk>    
     109         
     110        Mark an offline disk in the array as online again. The disk will begin 
     111        to resilver again automatically.  
    103112 
    104113List Options: 
     
    106115        list <zpool> 
    107116         
    108         Lists mirrored disks of a zpool 
    109  
    110 Usage: 
    111  
    112   lpreserver mirror <subcmd> <flags> 
    113  
    114 Example: 
    115  
    116   lpreserver mirror list tank1 
     117        Lists the connected disks of a zpool 
     118 
     119Usage: 
     120 
     121  lpreserver zpool <subcmd> <flags> 
     122 
     123Example: 
     124 
     125  lpreserver zpool list tank1 
    117126" 
    118127}; 
     
    388397           listsnap) help_listsnap ;; 
    389398           revertsnap) help_revertsnap ;; 
    390            mirror) help_mirror ;; 
     399           zpool) help_zpol ;; 
    391400           replicate) help_replicate ;; 
    392401           cronsnap) help_cronsnap ;; 
     
    489498            esac 
    490499         ;; 
    491     mirror) require_root 
     500    zpool) require_root 
    492501            shift 
    493502            case ${1} in 
    494                 add) add_mirror_disk "$2" "$3" ;; 
    495                 list) list_mirror_disks "$2" ;; 
    496                 remove) rem_mirror_disk "$2" "$3" ;; 
    497                 *) help_mirror ;; 
     503                attach) add_zpool_disk "$2" "$3" ;; 
     504                detach) rem_zpool_disk "$2" "$3" ;; 
     505                online) online_zpool_disk "$2" "$3" ;; 
     506               offline) offline_zpool_disk "$2" "$3" ;; 
     507                list) list_zpool_disks "$2" ;; 
     508                *) help_zpool ;; 
    498509            esac 
    499510         ;; 
  • src-qt4/life-preserver/LPBackend.cpp

    r845aaf6 r284b216  
    316316} 
    317317 
     318// ====================== 
     319//          Device Management 
     320// ====================== 
     321QStringList LPBackend::listDevices(){ 
     322  //Scan the system for all valid da* and ada* devices (USB/SCSI, SATA) 
     323  //Return format: "<device node> (<device information>)" 
     324  QDir devDir("/dev"); 
     325  QStringList devs = devDir.entryList(QStringList() << "da*"<<"ada*", QDir::System | QDir::NoSymLinks, QDir::Name); 
     326  QStringList camOut = LPBackend::getCmdOutput("camcontrol devlist"); 
     327  QStringList output, flist;     
     328  for(int i=0; i<devs.length(); i++){ 
     329    flist = camOut.filter("("+devs[i]+","); 
     330    //still need to add an additional device filter to weed out devices currently in use. 
     331    if(!flist.isEmpty()){ output << devs[i] + " ("+flist[0].section(">",0,0).remove("<").simplified()+")"; } 
     332  } 
     333  return output; 
     334} 
     335 
     336bool LPBackend::isMounted(QString device){ 
     337  qDebug() << "Device mount check not implemented yet"; 
     338  return false; 
     339} 
     340 
     341bool LPBackend::unmountDevice(QString device){ 
     342  qDebug() << "Device unmounting not implemented yet"; 
     343  return false; 
     344} 
    318345 
    319346// ========================= 
  • src-qt4/life-preserver/LPBackend.h

    r845aaf6 r284b216  
    3838        static QStringList findValidUSBDevices(); 
    3939        static bool copySSHKey(QString mountPath, QString localHost); 
     40        //Device Management 
     41        static QStringList listDevices(); 
     42        static bool isMounted(QString device); 
     43        static bool unmountDevice(QString device); 
     44        //Mirroring Management 
     45 
    4046         
    4147private: 
  • src-qt4/life-preserver/mainUI.cpp

    raac7789e r284b216  
    490490} 
    491491 
    492  
    493492// ============= 
    494493//      PROTECTED 
  • src-qt4/life-preserver/mainUI.ui

    r9a67431 r284b216  
    241241   </property> 
    242242  </action> 
     243  <action name="actionMirrorDataset"> 
     244   <property name="icon"> 
     245    <iconset resource="lPreserve.qrc"> 
     246     <normaloff>:/images/drive-removable-media.png</normaloff>:/images/drive-removable-media.png</iconset> 
     247   </property> 
     248   <property name="text"> 
     249    <string>Mirror Dataset to USB</string> 
     250   </property> 
     251  </action> 
    243252 </widget> 
    244253 <resources> 
Note: See TracChangeset for help on using the changeset viewer.