Ñò »µiVc@sCdZddkZddklZlZddkZddklZddk i Z ddk l Z l Z ddklZddklZlZlZlZlZddkZddkZddkZddkZddklZdad „Zd „Zeƒeid „ƒd „Zd „Z d„Z!d„Z"d„Z#de$d„Z%e$dd„Z&d„Z'd„Z(d„Z)d„Z*d„Z+d„Z,d„Z-d„Z.d„Z/dd„Z0e1d„Z2e1d„Z3dd„Z4d „Z5d!„Z6d"„Z7d#„Z8d$„Z9d%„Z:d&„Z;d'„Z<d(„Z=dde1d)„Z>dS(*s" PRIVATE ZFS HELPERS FOR BOOTMGMT iÿÿÿÿN(tcfunctconst(t LoggerMixin(tNVListtnvlistp(tNV_UNIQUE_NAME(t BootmgmtErrortBootmgmtZFSErrortBootmgmtArgumentErrortBootmgmtZFSPoolNotFoundErrortBootmgmtZFSPoolConflictError(tQueuecCstotStiƒatS(s (t __libzfshRt libzfs_init(((s%../../common/bootmgmt/zfs/__init__.pyR s cCs"totitƒdandS(s N(R Rt libzfs_finitNone(((s%../../common/bootmgmt/zfs/__init__.pyR(s cCstƒS((R(((s%../../common/bootmgmt/zfs/__init__.pyt3sc Csøtit|tiƒ}ti|tiƒidjoCt d|ti tƒdti tƒfdti tƒƒ‚nti||tƒ}zT|djoCt d|ti tƒdti tƒfdti tƒƒ‚nWdti|ƒXdS(sRenames the given datasetsFailed to open dataset %s: %ss: terrCodeisFailed to rename dataset %s: %sN(Rtzfs_openR RtZFS_TYPE_FILESYSTEMtCtcasttc_void_ptvalueRRtlibzfs_error_actiontlibzfs_error_descriptiont libzfs_errnot zfs_renametFalset zfs_close(told_dstnew_dstzfshtret((s%../../common/bootmgmt/zfs/__init__.pytrename_dataset5s cCs8ti|ƒ}|di|ƒ|d|||dƒS(Ntdsqueuetfunctarg(Rt zfs_get_nametput(tzhpR%tdsname((s%../../common/bootmgmt/zfs/__init__.pyt _zfs_iterfuncLscCstƒ}|i|ƒh|d6|d6|d6}xã|iƒpÕ|idtƒ}tit|ti ƒ}t i |t i ƒi d joCtd|titƒdtitƒfdtitƒƒ‚nz4ti|titƒ|ƒ}|djo|SWd ti|ƒXq4Wd S( s¡ Non-recursively iterates over all filesystems under the specified starting dataset, calling the specified callback with the specified argument. R$R%R#tblocksFailed to open dataset %s: %ss: RiN(R R'temptytgetRRRR RRRRRRRRRRRtzfs_iter_filesystemst ZFS_ITER_FR*R(tstart_dsR$R%R#targdicttdatasetR tretval((s%../../common/bootmgmt/zfs/__init__.pyR.Qs$      c CsazOy4tiƒtid|ƒ}|o |dSdSWntj odSXWdtiƒXdS(Nt mnt_specialt mnt_mountp(tpysolt mnttab_opent getmntanyRtIOErrort mnttab_close(R2tmntinfo((s%../../common/bootmgmt/zfs/__init__.pytdataset_mountpointls   cCs_titƒdjo'tiƒdjotitiƒƒStitƒdtitƒSdS(Nis: ( RRR Rt get_errnotoststrerrorRR(((s%../../common/bootmgmt/zfs/__init__.pytzfs_error_stringxs)c Cs­ddk}g}xŽ|D]†}|oPntii|ƒ}|idƒp|i|ƒqn|i|iƒdƒ}|o|i|ƒq|i|ƒqW|o |}nti ƒ}t |ƒ} t i | |Œ|_| |_ d|_d|_d|_d|_d|_titt i|ƒƒ} t| tƒ} d} xX| D]P} | | d} t| ƒtjpt| ƒtjo·d}x | D]¢}||djo‹|dtijowt|dƒti ƒjoZd |jo%|d |jo|} |d }q8d |jo|djo |} q8q–q–WqO|| djoN| dtijo:t| dƒti ƒjo| p| | d} qŸqOqOW| pjti!tƒ}|dti"gjot#|ƒ‚qt$d |t|ƒt%ƒfd ti!tƒƒ‚ntƒ}|o.x+|D]}|i&|ƒ||d ftpathtabspatht startswithtappendtstriptextendRt ImportArgstlenRtc_char_ptpathsRtpoolnamet cachefiletuniquetguidt trust_cachetzpool_search_importR tbyrefRRttypetlistttupleRtPOOL_STATE_DESTROYEDtstrR6t get_hostidRt EZFS_NOENTR RR@R-tzpool_import_propstZFS_IMPORT_ONLY(RRtdevlistt poolpropstliteral_devlistRGt newdevlisttdevRQtiargst devlist_lentpoolst found_pooltpooltpoolnvlREtdup_pooltzfs_errtpropnvltkeyterr((s%../../common/bootmgmt/zfs/__init__.pyt zpool_import€s†           &  !   #cCsþg}hdti6dti6dti6dti6}g}|ti}|ti}t|ƒdjp*|dtiti ti ti gjo t i d|dtiƒd S|dtiti jo|dti}nxÔ|D]Ì}t i d|ƒ|ot|ƒ} n|ti} |djoxd} xX|iƒD]J} y.|| o|| | jo|| } nWqBtj oqBXqBW|i| | fƒqè|i| ƒqèW|o;t|dd „ƒ}g} |D]\} }| | qß~ S|S( s Convert a ZFS pool configuration (stored as an nvlist) to a list of constituent disk devices. This is only to be used on pool with a single top-level mirror vdev and disk/file children under that vdev, OR a single disk/file top-level vdev. iiiis&Invalid pool -- top level vdev is a %ss Child: %sthealthRpcSs|dS(i((tx((s%../../common/bootmgmt/zfs/__init__.pyR sN(RtZPOOL_CONFIG_DEGRADEDtZPOOL_CONFIG_OFFLINEtZPOOL_CONFIG_FAULTEDtZPOOL_CONFIG_REMOVEDtZPOOL_CONFIG_VDEV_TREEtZPOOL_CONFIG_CHILDRENROtZPOOL_CONFIG_TYPEtVDEV_TYPE_MIRRORtVDEV_TYPE_FILEtVDEV_TYPE_DISKRt_debugRtzfs_get_adjusted_pathtZPOOL_CONFIG_PATHtkeystKeyErrorRKtsorted(tnvlt wholedisktsorttsortlistt healthmapRbt vdev_treetchildrentchildRftsortvalRtt_[1]titj((s%../../common/bootmgmt/zfs/__init__.pytzpool_config_to_listßsH      !     &cCs’ti|jos|tioe|ti}|idƒ}|djo7||diƒo|| }tid|ƒq~n|S|tiSdS(s tsiÿÿÿÿisChild[wholedisk] => %sN(RtZPOOL_CONFIG_WHOLE_DISKRtrfindtisdigitRR(RŒRftlast_s((s%../../common/bootmgmt/zfs/__init__.pyR€s   cCst|dtƒS(s R†(R‘tTrue(R…((s%../../common/bootmgmt/zfs/__init__.pytzpool_config_to_disklist scCs t|ƒS(s (R‘(R…((s%../../common/bootmgmt/zfs/__init__.pytzpool_config_to_partlist%scCst|ddƒS(s R‡Rs(R‘(R…((s%../../common/bootmgmt/zfs/__init__.pytzpool_config_to_healthlist*scCsdtit|ƒ}ti|tiƒidjo"titƒt i jot Snti |ƒt S(s N(Rtzpool_open_canfailR RRRRRRRR_Rt zpool_closeR—(RRtzph((s%../../common/bootmgmt/zfs/__init__.pyt zpool_exists/s   cCsötit|tiƒ}ti|tiƒidjoCt d|ti tƒdti tƒfdti tƒƒ‚nti|||ƒ}ti|ƒ|djoIt d|||ti tƒdti tƒfdti tƒƒ‚ndS(s sFailed to open dataset %s: %ss: Ris3Couldn't set zfs property %s=%s for dataset %s (%s)N(RRR RRRRRRRRRRRt zfs_prop_setR(R2tpropnametpropvalR Rq((s%../../common/bootmgmt/zfs/__init__.pyt zfs_set_prop=s   cCstit|tiƒ}ti|tiƒidjoCt d|ti tƒdti tƒfdti tƒƒ‚nti||ƒ}ti|ƒ|S(sQ Returns the named property (in integer form) from the specified dataset sFailed to open dataset %s: %ss: RN(RRR RRRRRRRRRRRtzfs_prop_get_intR(R2R R tval((s%../../common/bootmgmt/zfs/__init__.pyR£Us cCstit|tiƒ}ti|tiƒidjoCt d|ti tƒdti tƒfdti tƒƒ‚nti|ƒ}ti|tiƒidjoti|ƒdSt|tƒ}y||d}Wntj o d}nXti|ƒ|S(sP Returns the named property (in string form) from the specified dataset sFailed to open dataset %s: %ss: RRN(RRR RRRRRRRRRRRtzfs_get_user_propsRRRRƒ(R2R R tnvlpR…R3((s%../../common/bootmgmt/zfs/__init__.pytzfs_get_user_propis"   cCsOti}ti||ƒptd|ƒ‚ntit||ƒotStS(s sInvalid dataset name: %s( RRRtzfs_name_validRtzfs_dataset_existsR R—R(R2tcrtype((s%../../common/bootmgmt/zfs/__init__.pytdataset_existsƒs  cCsTti}ti||ƒptd|ƒ‚ntit||ƒodStit|ƒdjoCtd|ti tƒdti tƒfdti tƒƒ‚n|o:t ƒ}x4|i ƒD]\}}|||dfR?(torigtlibnvptdupRq((s%../../common/bootmgmt/zfs/__init__.pyR¿ÿs   cCs tit|ƒ}ti|tiƒidjoCtd|ti tƒdti tƒfdti tƒƒ‚nti |dƒ}ti|tiƒidjoCti tƒdti tƒ}td|dti tƒƒ‚nt t|ƒƒ}ti|ƒ|S(sC Return the zpool configuration nvlist for the given pool. sFailed to open pool %s: %ss: RsFailed to get zpool config (%s)N(RR›R RRRRRRRRRtzpool_get_configRR¿Rœ(RRRtconfigterr_strR3((s%../../common/bootmgmt/zfs/__init__.pyRÉs  c Cstit|ƒ}ti|tiƒid joCtd|ti tƒdti tƒfdti tƒƒ‚nti |d ƒ}ti|tiƒid joPti tƒdti tƒ}ti |ƒtd|dti tƒƒ‚nt|tƒ}|ti}|ti}|dti}|tijoVt|ƒdjoti |ƒtdƒ‚n|dti}|dti}n|titigjot|dƒ} nti |ƒtdƒ‚g} g} x|D] } tit|tdtttidtid| ƒƒ } | d joDti tƒdti tƒ}| i| d| |ffƒqînti|| | | tƒ}|oOd ti tƒd| |f}|ti tƒd 7}| i| |fƒqî| i| ƒqîWti |ƒ| | fS( sG Add the specified list of devices to the specified boot pool. sFailed to open pool %s: %ss: RsFailed to get zpool config (%s)iis#Invalid boot pool ZFS configurations$Failed to make root vdev for %s (%s)s'Failed to attach %s to boot pool `%s' (s) N(Rt zpool_openR RRRRRRRRRRÉRœRRRRyRzR{R|ROR~R}R€tzpool_make_root_vdevR—tZPOOL_LABEL_MATCH_REQ_PARTRPRKtzpool_vdev_attach(RRt device_listRRÊRËt confignvlRŠt children_nvltpooltypetotherdevtfailedtsuccesstdevicetnvrootRq((s%../../common/bootmgmt/zfs/__init__.pytadd_devices_to_pool'sl           cCs#tit|ƒ}ti|tiƒidjoCtd|ti tƒdti tƒfdti tƒƒ‚ng}g}x‰|D]}ti ||ƒ}|djoOdti tƒd||f}|ti tƒd7}|i ||fƒq‡|i |ƒq‡Wti|ƒ||fS(s˜ Remove the specified devices from the boot pool. Returns a tuple of two lists, [0] = devices successfully removed, and [1] = not removed. sFailed to open pool %s: %ss: Ris)Failed to remove %s from boot pool `%s' (s) N(RRÌR RRRRRRRRRtzpool_vdev_detachRKRœ(RRRÐRRÖRÕR×RqRË((s%../../common/bootmgmt/zfs/__init__.pytremove_devices_from_poolxs$ ! cCsQtit|ƒ}|idjoCtd|titƒdtitƒfdtitƒƒ‚nti |t ƒdjoVtitƒdtitƒ}ti |ƒtd||fdtitƒƒ‚nti |ƒdjoVtitƒdtitƒ}ti |ƒtd||fdtitƒƒ‚nti |ƒdS(s+ Destroys the named pool forcibly. sFailed to open pool %s (%s)s: Ris*Failed to disable datasets in pool %s (%s)sFailed to destroy pool %s (%s)N( RR›R tcontentsRRRRRtzpool_disable_datasetsR—Rœt zpool_destroy(RRRRË((s%../../common/bootmgmt/zfs/__init__.pyt destroy_pool˜s&  # #cCstit|ƒ}ti|tiƒidjoCtd|ti tƒdti tƒfdti tƒƒ‚nti |ƒt ij}ti|ƒ|S(s,Returns true if the pool is unavailable sFailed to open pool %s (%s)s: RN(RR›R RRRRRRRRRtzpool_get_stateRtPOOL_STATE_UNAVAILRœ(RRRtunavail((s%../../common/bootmgmt/zfs/__init__.pytis_pool_unavail¶s  cCs t|dƒS(s+Returns the bootfs pool property value tbootfs(tzpool_prop_get(RR((s%../../common/bootmgmt/zfs/__init__.pytzpool_get_bootfsÆscCs²tit|ƒ}ti|tiƒidjo"titƒt i jot Snti t i ƒ}ti|ti|ƒ|t i dƒ}ti|ƒ|djodS|iS(s iN(RR›R RRRRRRRR_Rtcreate_string_buffertZFS_MAXPROPLENtzpool_get_proptzpool_name_to_propRœ(RRR RtbufRq((s%../../common/bootmgmt/zfs/__init__.pyRåÌs   cCstit|ƒ}ti|tiƒidjo"titƒt i jot Snti |||ƒ}ti |ƒ|djot StSdS(s iN(RR›R RRRRRRRR_Rtzpool_set_propRœR—(RRR R¤RRq((s%../../common/bootmgmt/zfs/__init__.pytzpool_prop_setßs   cCstdtƒ}tdtƒ}titiƒ}d||df|D]6} t i i | ƒpRxgdddgD]:} | i d d ƒ| } t i i | ƒ}|oPqqWn| i d d ƒ} t}|o¬yzt i| ƒ}ti|iƒo |i}n*ti|iƒoti| ƒ}nwî|djo| i| ƒnWq$tj o}tid | |fƒq$XqîqîWt| ƒt|ƒjo | }tidt| ƒƒnt|ƒdjotdƒ‚nt|ƒdjo dg}ng}|i|ƒt|ƒ}titd||odndt t ti!|t"i#||Œƒ }t"i$|t"i%ƒi&djooti'tƒ}|ti(jot)|dƒ‚ntd|ti*tƒdti+tƒ|fd|ƒ‚nti,t||||ƒ}|djoCtd|ti*tƒdti+tƒfdti'tƒƒ‚ndS(s‰ Create the named boot pool with the specified pool and top-level dataset properties. Autoreplace is automatically enabled. tflagstnoneRFt1tontp0ts2ts0s/dsk/s/rdsk/idisError getting size for %s: %ss/Device list changed for create: New list is: %sis0No valid devices supplied to build the boot poolitmirrors4Could not create the boot pool due to in-use devicess;Failed to create root vdevs for boot pool %s (%s (code %d))s: RsFailed to create pool %s (%s)Nii@(-RRRtzfs_prop_to_nameRtZFS_PROP_MOUNTPOINTtZFS_PROP_USER_BOOTABLEtzpool_prop_to_nametZPOOL_PROP_AUTOREPLACERR>RHtexiststreplaceR—tstattS_ISREGtst_modetst_sizetS_ISCHRR6traw_device_sizeRKR9RRROR]RRMRÍR RtZPOOL_LABEL_REQ_PARTRRPRRRRtEZFS_DEV_INUSER RRt zpool_create(RRt devicelistRct userpropsR·R¯tfspropstmntpttautorepltpropReR×tsuffixt check_deviceRûtsbtsizetioerrtargstargslent config_nvlptcodeRq((s%../../common/bootmgmt/zfs/__init__.pytcreate_boot_poolñs˜             $  (?t__doc__tctypesRtbootmgmt.zfs.libzfsRRtbootmgmt.bootutiltbootmgmtRtbootmgmt.pysolR6t libnvpairRRtlibnvpair.constRRRRR R R>RýtatexitRÀR RR R RtregisterR"R*R.R<R@RRrR‘R€R˜R™RšRžR¢R£R§R«R°R—RºR´R»R¿RÉRÙRÛRßRãRæRåRíR(((s%../../common/bootmgmt/zfs/__init__.pytsb  (         _2          "      Q