Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ATA disk mapping, zpool check, netdev check, and a config file #15

Merged
merged 26 commits into from
Jun 21, 2024

Conversation

miskcoo
Copy link
Owner

@miskcoo miskcoo commented Jun 20, 2024

  • Add the config file /etc/ugreen-leds.conf for environment variables used in ugreen-diskiomon (see scripts/ugreen-leds.conf)
  • Make the blinking of netdev activities, colors of different disk states / NIC link speeds configurable
  • Add the check of zpool health
  • Add the check of gateway connectivity and the link speed of network device
  • Split the systemd service to ugreen-diskiomon.service and ugreen-netdevmon@<device name>.service
  • HCTL mapping will fail in some cases (hctl mapping for SATA drives only #14), UGOS uses ATA number to map disks to slots. I changed the default mapping to ATA, which can be shown by the following scripts:
# ATA Mapping
ls -ahl /sys/block | sed 's/\/$//' |  awk '{
    if (match($0, /ata[0-9]+/)) {
        ata = substr($0, RSTART, RLENGTH);
        if (match($0, /[^\/]+$/)) {
            basename = substr($0, RSTART, RLENGTH);
        }
        print basename, ata;
    }
}'

# HCTL Mapping
lsblk -S -o name,hctl -x hctl

Below are some de-compiled codes of hwmonitor in UGOS, so I think the ATA mapping would be a good choice:

int diskGetAllSataDiskName(long param_1)
{
  int iVar1;
  int iVar2;
  int iVar3;
  undefined4 local_2e;
  undefined2 local_2a;
  
  iVar2 = 0;
  local_2e = 0x31617461;   // this is "ata1"
  local_2a = 0;
  for (iVar3 = 0; iVar3 < g_DISK_TOTAL; iVar3 = iVar3 + 1) {
    local_2e = CONCAT13((char)iVar3 + '1',(undefined3)local_2e);  // concat_string("ata", iVat3 + '1')
    iVar1 = getDevNameByInterface(&local_2e,*(undefined8 *)(param_1 + (long)iVar2 * 8));
    iVar2 = (iVar2 + 1) - (uint)(iVar1 == 0);
  }
  return iVar2;
}

undefined8 getDevNameByInterface(char *param_1,char *param_2)
{
  char *__s1;
  int iVar1;
  DIR *__dirp;
  dirent *pdVar2;
  ssize_t sVar3;
  char *pcVar4;
  undefined8 uVar5;
  char local_d8 [32];
  char local_b8 [136];
  
  if ((param_1 != (char *)0x0) && (param_2 != (char *)0x0)) {
    __dirp = opendir("/sys/block");
    if (__dirp != (DIR *)0x0) {
      do {
        do {
          pdVar2 = readdir(__dirp);
          if (pdVar2 == (dirent *)0x0) {
            uVar5 = 0xffffffff;
            goto LAB_0010632c;
          }
          __s1 = pdVar2->d_name;
          iVar1 = strncmp(__s1,"sd",2);
        } while ((iVar1 != 0) && (iVar1 = strncmp(__s1,"nvme",4), iVar1 != 0));
        snprintf(local_d8,0x20,"/sys/block/%s",__s1);
        sVar3 = readlink(local_d8,local_b8,0x80);
      } while ((sVar3 == -1) || (pcVar4 = strstr(local_b8,param_1), pcVar4 == (char *)0x0));
      uVar5 = 0;
      snprintf(param_2,0x20,"/dev/%s",__s1);
LAB_0010632c:
      closedir(__dirp);
      return uVar5;
    }
    xlog_out(0,"disk.c","getDevNameByInterface",0x16e,"open /sys/block failed!\n");
  }
  return 0xffffffff;
}

@miskcoo
Copy link
Owner Author

miskcoo commented Jun 20, 2024

Hope someone with other devices can test the new script (especially those have DXP6800), and check the outputs of the above commands. It uses the ATA mapping by default.

@miskcoo miskcoo linked an issue Jun 20, 2024 that may be closed by this pull request
@miskcoo miskcoo changed the title add ATA disk mapping and create a config file for environment variables of ugreen-diskiomon add ATA disk mapping, zpool check, and a config file Jun 20, 2024
@sgreiner
Copy link

Awesome! ugreen-netdevmon@.service working fine, including gateway check and link speed detection and colors.

@sgreiner
Copy link

Hope someone with other devices can test the new script (especially those have DXP6800), and check the outputs of the above commands. It uses the ATA mapping by default.

I can confirm the correctness for DXP6800 for these two mappings
hctl_map=("2:0:0:0" "3:0:0:0" "4:0:0:0" "5:0:0:0" "0:0:0:0" "1:0:0:0")
ata_map=("ata3" "ata4" "ata5" "ata6" "ata1" "ata2")

for i in "${!led_map[@]}"; do
led=${led_map[i]}
if [[ -d /sys/class/leds/$led ]]; then
echo oneshot > /sys/class/leds/$led/trigger
echo 1 > /sys/class/leds/$led/invert
echo 100 > /sys/class/leds/$led/delay_on
echo 100 > /sys/class/leds/$led/delay_off
echo "255 255 255" > /sys/class/leds/$led/color
echo "$COLOR_DISK_HEALTH" > /sys/class/leds/$led/color

# find corresponding device
_tmp_str=${MAPPING_METHOD}_map[@]
_tmp_arr=(${!_tmp_str})
dev=${dev_map[${_tmp_arr[i]}]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I get two errors: (because I only have 6 and not 8 disk slots)
/usr/bin/ugreen-diskiomon: line 147: dev_map: bad array subscript
/usr/bin/ugreen-diskiomon: line 147: dev_map: bad array subscript

DEBUG: _tmp_arr[0]='ata3'
DEBUG: _tmp_arr[1]='ata4'
DEBUG: _tmp_arr[2]='ata5'
DEBUG: _tmp_arr[3]='ata6'
DEBUG: _tmp_arr[4]='ata1'
DEBUG: _tmp_arr[5]='ata2'
DEBUG: _tmp_arr[6]=''
DEBUG: _tmp_arr[7]=''

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fixed now

@dieneuser
Copy link

dieneuser commented Jun 21, 2024

DX4600*) # tested on DX4600 Pro

There is no model series DX4600, the correct series would be DXP4800 (Plus).

        DXP4800*)   # tested on DXP4800 Plus
            echo "Found UGREEN DXP4800 series" 

@miskcoo
Copy link
Owner Author

miskcoo commented Jun 21, 2024

DX4600*) # tested on DX4600 Pro

There is no model series DX4600, the correct series would be DXP4800 (Plus).

        DXP4800*)   # tested on DXP4800 Plus
            echo "Found UGREEN DXP4800 series" 

Oh, my model is 4600, it is a version sold only in China (~2023).

@dieneuser
Copy link

dieneuser commented Jun 21, 2024

DX4600*) # tested on DX4600 Pro

There is no model series DX4600, the correct series would be DXP4800 (Plus).

        DXP4800*)   # tested on DXP4800 Plus
            echo "Found UGREEN DXP4800 series" 

Oh, my model is 4600, it is a version sold only in China (~2023).

Oh how interesting, then the block has to be expanded to include the 4800 models.

@miskcoo miskcoo changed the title add ATA disk mapping, zpool check, and a config file add ATA disk mapping, zpool check, netdev check, and a config file Jun 21, 2024
@miskcoo miskcoo merged commit 522f93b into master Jun 21, 2024
@miskcoo miskcoo deleted the ata-disk-mapping branch June 21, 2024 19:26
miskcoo added a commit that referenced this pull request Jun 22, 2024
@miskcoo miskcoo mentioned this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hctl mapping for SATA drives only
4 participants