From 38be98d9f1d2e5eb1686f9d357254b133941138d Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 9 Jul 2025 14:56:43 +0200 Subject: [PATCH] refs #2436 add new function to obtain disk I/O size --- ogclient/interfaceAdm/Configurar.py | 5 ++- ogclient/lib/python3/CacheLib.py | 22 ++++++------ ogclient/lib/python3/DiskLib.py | 56 ++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/ogclient/interfaceAdm/Configurar.py b/ogclient/interfaceAdm/Configurar.py index 7934ce1..63a4bf8 100755 --- a/ogclient/interfaceAdm/Configurar.py +++ b/ogclient/interfaceAdm/Configurar.py @@ -151,7 +151,10 @@ if not recreate_partition_table and not CacheLib.ogCheckNewCacheSize (dis, tch): ## size check: check that the newly defined partitions fit in the space left by the newly defined cache disk_sectors = DiskLib.ogGetLastSector (dis) -IOSIZE = 512 ## TODO +IOSIZE = DiskLib.ogGetIoSize (dis) +if not IOSIZE: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Failed to get disk sector size') + sys.exit (1) if 512 == IOSIZE: sum_tam_sectors = sum_tam*2 cache_sectors = tch*2 diff --git a/ogclient/lib/python3/CacheLib.py b/ogclient/lib/python3/CacheLib.py index a7bf170..f5ca0bb 100644 --- a/ogclient/lib/python3/CacheLib.py +++ b/ogclient/lib/python3/CacheLib.py @@ -42,14 +42,10 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0): return None SIZE = 2 * sizecache # Inicio partición cache según el disco tenga sectores de 4k o menores - IOSIZE = 0 - fdisk_out = subprocess.run (['fdisk', '-l', DISK], capture_output=True, text=True).stdout - for l in fdisk_out.splitlines(): - items = l.split() - if len(items) < 4: continue - if 'I/O' == items[0]: - IOSIZE = int (items[3]) - break + IOSIZE = DiskLib.ogGetIoSize (DISK) + if not IOSIZE: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Failed to get disk sector size') + return None START = 0 if 4096 == IOSIZE: END -= 8192 @@ -373,7 +369,13 @@ def initCache (*args): #@return Boolean, True si la nueva cache cabría, False si no #*/ ## def ogCheckNewCacheSize (disk, kB): - IOSIZE=512 #DiskLib.blablaIoSize (disk) + DISK = DiskLib.ogDiskToDev (disk) + if not DISK: return None + + IOSIZE = DiskLib.ogGetIoSize (disk) + if not IOSIZE: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Failed to get disk sector size') + return None last_sector = DiskLib.ogGetLastSector (disk) end_of_last_partition = 0 @@ -383,7 +385,7 @@ def ogCheckNewCacheSize (disk, kB): cache_dev = DiskLib.ogDiskToDev (cache_disk, cache_part) else: cache_dev = None - fdisk_l_out = subprocess.run (['fdisk', '-l'], capture_output=True, text=True).stdout + fdisk_l_out = subprocess.run (['fdisk', '-l', DISK], capture_output=True, text=True).stdout for l in fdisk_l_out.splitlines(): if not re.match ('^/dev', l): ## no empieza por /dev, nos la saltamos continue diff --git a/ogclient/lib/python3/DiskLib.py b/ogclient/lib/python3/DiskLib.py index 0510f29..dc47b89 100644 --- a/ogclient/lib/python3/DiskLib.py +++ b/ogclient/lib/python3/DiskLib.py @@ -38,6 +38,34 @@ def parted(*args): return "Error: 'parted' command not found" +#/** +# ogGetIoSize int_ndisk +#@brief Devuelve el tamaño de sector de un disco +#@param int_ndisk nº de orden del disco +#@return Tamaño de sector +#*/ ## +def ogGetIoSize (disk): + DISK = ogDiskToDev (disk) + if not DISK: return None + + IOSIZE = None + print (f'nati ejecutando fdisk -l') + fdisk_out = subprocess.run (['fdisk', '-l', DISK], capture_output=True, text=True).stdout + for l in fdisk_out.splitlines(): + if 'I/O' not in l: continue + items = l.split() + if len(items) < 4: continue + IOSIZE = items[3] + print (f'nati detectado IOSIZE ({IOSIZE})') + break + + if IOSIZE is None: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Could not extract disk sector size from fdisk output') + return None + + return int (IOSIZE) + + #/** # ogCreatePartitions int_ndisk str_parttype:int_partsize ... #@brief Define el conjunto de particiones de un disco. @@ -79,21 +107,17 @@ def ogCreatePartitions (disk, parts): CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2 # Sector de inicio (la partición 1 empieza en el sector 63). - IOSIZE = 0 - fdisk_out = subprocess.run (['fdisk', '-l', DISK], capture_output=True, text=True).stdout - for l in fdisk_out.splitlines(): - if 'I/O' not in l: continue - items = l.split() - if len(items) < 4: continue - IOSIZE = items[3] - break + IOSIZE = ogGetIoSize (ND) + if not IOSIZE: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Failed to get disk sector size') + return None - if '4096' == IOSIZE: + if 4096 == IOSIZE: START = 4096 SECTORS -= 8192 if CACHESIZE: SECTORS = SECTORS - CACHESIZE + 2048 - (SECTORS - CACHESIZE) % 2048 - 1 - else: + else: ## 512 if 'MSDOS' == PTTYPE: START = 63 else: START = 2048 if CACHESIZE: @@ -120,7 +144,6 @@ def ogCreatePartitions (disk, parts): if f'{ND} {PART}' == CACHEPART and CACHESIZE: sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, type={CACHE_ID}\n' PART += 1 - #continue try: SIZE = int (SIZE) @@ -132,10 +155,9 @@ def ogCreatePartitions (disk, parts): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, TYPE) return None - # Comprobar tamaño numérico y convertir en sectores de 512 B. ## BUG!! qué pasa si IOSIZE==4096 - SIZE *= 2 - - ## TODO ojo, no puede haber dos extendidas + # Comprobar tamaño numérico y convertir en sectores + if 512 == IOSIZE: SIZE *= 2 + else: SIZE = (SIZE+3)//4 ## sumamos 3 para que la división entera "redondee al alza" # Comprobar si la partición es extendida. if '5' == ID: @@ -185,7 +207,7 @@ def ogCreatePartitions (disk, parts): START += SIZE - if 'MSDOS' == PTTYPE and '4096' == IOSIZE and PART > 4: + if 'MSDOS' == PTTYPE and 4096 == IOSIZE and PART > 4: START += 2048 # Error si se supera el nº total de sectores. @@ -809,7 +831,7 @@ def ogGetPartitionSize (disk, par): #@return Devuelve el numero paritiones del disco duro indicado #@warning Salidas de errores no determinada #@attention Requisitos: parted -#@note Notas sin especificar +#@note Notas sin especificar #*/ ## def ogGetPartitionsNumber (disk): DISK = ogDiskToDev (disk)