refs #1779 fix some bugs, remove internal debug stuff
parent
d748bb18d1
commit
ee164eda7b
|
@ -147,7 +147,10 @@ if not cur_ptt or ptt != cur_ptt:
|
|||
if 'CACHE' in sparam:
|
||||
SystemLib.ogEcho (['session', 'log'], None, f'[30] {ogGlobals.lang.MSG_HELP_ogCreateCache}')
|
||||
SystemLib.ogEcho (['session', 'log'], None, f' initCache {tch}')
|
||||
SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
|
||||
rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
|
||||
if rc:
|
||||
SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed')
|
||||
sys.exit (1)
|
||||
|
||||
# Definir particionado.
|
||||
SystemLib.ogEcho (['session', 'log'], None, f'[50] {ogGlobals.lang.MSG_HELP_ogCreatePartitions}')
|
||||
|
|
|
@ -60,11 +60,9 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
prev_part = part - i
|
||||
if prev_part <= 0: break
|
||||
ENDPREVPART = DiskLib.ogGetLastSector (ndsk, prev_part)
|
||||
print (f'nati got endprevpart ({ENDPREVPART})')
|
||||
if ENDPREVPART: break
|
||||
i += 1
|
||||
if not ENDPREVPART:
|
||||
print (f'nati no endprevpart, assuming 0')
|
||||
ENDPREVPART=0
|
||||
#SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
|
||||
#return None
|
||||
|
@ -72,7 +70,6 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
MINSIZE = 25000
|
||||
MAXSIZE = END
|
||||
if SIZE < MINSIZE or SIZE > MAXSIZE or START < ENDPREVPART:
|
||||
print (f'nati size ({SIZE}) < minsize ({MINSIZE}) or size > maxsize ({MAXSIZE}) or start ({START}) < endprevpart ({ENDPREVPART})')
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
|
||||
return None
|
||||
|
||||
|
@ -82,23 +79,20 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
# En el caso de ser disco GPT, de momento se borra la particion y se vuelve a crear,
|
||||
# por lo que se pierden los datos.
|
||||
pttype = DiskLib.ogGetPartitionTableType (ndsk)
|
||||
print (f'nati pttype ({pttype})')
|
||||
if not pttype:
|
||||
pttype = 'MSDOS'
|
||||
DiskLib.ogCreatePartitionTable (ndsk, pttype)
|
||||
|
||||
get_ptt = DiskLib.ogGetPartitionTableType (ndsk)
|
||||
print (f'nati get_ptt ({get_ptt})')
|
||||
if 'GPT' == get_ptt:
|
||||
# Si la tabla de particiones no es valida, volver a generarla.
|
||||
if subprocess.run (['sgdisk', '-p', DISK]).returncode:
|
||||
subprocess.run (['gdisk', DISK], input='2\nw\nY\n', text=True)
|
||||
if subprocess.run (['sgdisk', '-p', DISK], capture_output=True, text=True).returncode:
|
||||
subprocess.run (['gdisk', DISK], input='2\nw\nY\n', capture_output=True, text=True)
|
||||
# Si existe la cache se borra previamente
|
||||
if ogFindCache(): ogDeleteCache()
|
||||
# Capturamos el codigo de particion GPT para cache
|
||||
# PATCH - Cuando es GPT, la particion con codigo CACHE (CA00) no existe y no puede crearse, se cambia por LINUX (8300)
|
||||
ID = DiskLib.ogTypeToId ('LINUX', 'GPT')
|
||||
print (f'nati ID ({ID})')
|
||||
subprocess.run (['sgdisk', DISK, f'-n{part}:{START}:{END}', f'-c{part}:CACHE', f'-t{part}:{ID}'])
|
||||
elif 'MSDOS' == get_ptt:
|
||||
# Si la tabla de particiones no es valida, volver a generarla.
|
||||
|
@ -106,7 +100,6 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
subprocess.run (['fdisk', DISK], input='w\n', text=True)
|
||||
# Definir particiones y notificar al kernel.
|
||||
ID = DiskLib.ogTypeToId ('CACHE', 'MSDOS')
|
||||
print (f'nati ID ({ID})')
|
||||
# Salvamos la configuración de las particiones e incluimos la cache.
|
||||
tmp = subprocess.run (['sfdisk', '--dump', DISK], capture_output=True, text=True).stdout.splitlines()
|
||||
tmp = [ x for x in tmp if f'{DISK}{part}' not in x ]
|
||||
|
@ -117,10 +110,10 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
tmp = [UNIT, ''] + tmp
|
||||
# Guardamos nueva configuración en el disco.
|
||||
i = '\n'.join(tmp)
|
||||
print (f'nati i ({i})')
|
||||
subprocess.run (['sfdisk', '--no-reread', DISK], input=i, text=True)
|
||||
# Actualiza la tabla de particiones en el kernel.
|
||||
DiskLib.ogUpdatePartitionTable()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ def ogCreatePartitions (disk, parts):
|
|||
CACHEPART = CacheLib.ogFindCache()
|
||||
if CACHEPART:
|
||||
cache_disk, cache_part = CACHEPART.split()
|
||||
if ND == cache_disk:
|
||||
if ND == int (cache_disk):
|
||||
CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2
|
||||
# Sector de inicio (la partición 1 empieza en el sector 63).
|
||||
IODISCO = ogDiskToDev (disk)
|
||||
|
@ -100,7 +100,6 @@ def ogCreatePartitions (disk, parts):
|
|||
SECTORS -= CACHESIZE
|
||||
|
||||
PART = 1
|
||||
print (f'START ({START}) SECTORS ({SECTORS}) PART ({PART})')
|
||||
|
||||
sfdisk_input = 'unit: sectors\n\n'
|
||||
NVME_PREFIX = 'p' if 'nvme' in DISK else ''
|
||||
|
@ -109,6 +108,7 @@ def ogCreatePartitions (disk, parts):
|
|||
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
||||
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n'
|
||||
PART += 1
|
||||
continue
|
||||
|
||||
# Leer formato de cada parámetro - Tipo:Tamaño
|
||||
TYPE, SIZE = p.split (':')
|
||||
|
@ -176,9 +176,7 @@ def ogCreatePartitions (disk, parts):
|
|||
ogCreatePartitionTable (ND)
|
||||
|
||||
# Definir particiones y notificar al kernel.
|
||||
#print (f'nati: about to run sfdisk: ({sfdisk_input})')
|
||||
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
|
||||
#print (f'nati: rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
|
||||
subprocess.run (['partprobe', DISK])
|
||||
if CACHESIZE: CacheLib.ogMountCache()
|
||||
return True
|
||||
|
@ -284,9 +282,7 @@ def ogCreateGptPartitions (disk, parts):
|
|||
ogCreatePartitionTable (ND, 'GPT')
|
||||
|
||||
# Definir particiones y notificar al kernel.
|
||||
#print (f'nati: about to run sgdisk ({DELOPTIONS}) ({OPTIONS}) ({DISK})')
|
||||
p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK])
|
||||
#print (f'nati: rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
|
||||
p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK], capture_output=True, text=True)
|
||||
subprocess.run (['partprobe', DISK])
|
||||
if CACHESIZE: CacheLib.ogMountCache()
|
||||
return True
|
||||
|
@ -818,7 +814,7 @@ def ogGetPartitionId (disk, par):
|
|||
if fsid == '8300' and f'{disk} {par}' == CacheLib.ogFindCache():
|
||||
fsid = 'CA00'
|
||||
elif 'MSDOS' == pttype:
|
||||
fsid = subprocess.run (['sfdisk', '--part-type', DISK, par], capture_output=True, text=True).stdout.strip()
|
||||
fsid = subprocess.run (['sfdisk', '--part-type', DISK, str(par)], capture_output=True, text=True).stdout.strip()
|
||||
elif 'LVM' == pttype:
|
||||
fsid = '10000'
|
||||
elif 'ZPOOL' == pttype:
|
||||
|
|
|
@ -48,7 +48,9 @@ def main (NDISK, NPART, SIZE, MOUNT):
|
|||
print("[10] Crear partición de caché local.")
|
||||
CacheLib.ogUnmountCache()
|
||||
print (f'nati: calling ogCreateCache ({NDISK}, {NPART}, {SIZE})')
|
||||
CacheLib.ogCreateCache (NDISK, NPART, SIZE)
|
||||
if not CacheLib.ogCreateCache (NDISK, NPART, SIZE):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_CACHE, 'failed to create cache')
|
||||
return False
|
||||
DiskLib.ogUpdatePartitionTable()
|
||||
|
||||
# Si caché no montada y no formateada o cambia el tamaño: formatear.
|
||||
|
|
Loading…
Reference in New Issue