"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "platform-intel.c" between
mdadm-4.2-rc1.tar.xz and mdadm-4.2-rc2.tar.xz

About: mdadm is a tool for creating, managing and monitoring device arrays using the "md" driver in Linux, also known as Software RAID arrays.

platform-intel.c  (mdadm-4.2-rc1.tar.xz):platform-intel.c  (mdadm-4.2-rc2.tar.xz)
skipping to change at line 242 skipping to change at line 242
n = read(fd, vendor, sizeof(vendor)); n = read(fd, vendor, sizeof(vendor));
if (n == sizeof(vendor)) { if (n == sizeof(vendor)) {
vendor[n - 1] = '\0'; vendor[n - 1] = '\0';
id = strtoul(vendor, NULL, 16); id = strtoul(vendor, NULL, 16);
} }
close(fd); close(fd);
return id; return id;
} }
/* Description: Read text value of dev_path/entry field
* Parameters:
* dev_path - sysfs path to the device
* entry - entry to be read
* buf - buffer for read value
* len - size of buf
* verbose - error logging level
*/
int devpath_to_char(const char *dev_path, const char *entry, char *buf, int len,
int verbose)
{
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s/%s", dev_path, entry);
if (load_sys(path, buf, len)) {
if (verbose)
pr_err("Cannot read %s, aborting\n", path);
return 1;
}
return 0;
}
struct sys_dev *find_intel_devices(void) struct sys_dev *find_intel_devices(void)
{ {
struct sys_dev *ahci, *isci, *nvme; struct sys_dev *ahci, *isci, *nvme;
if (valid_time > time(0) - 10) if (valid_time > time(0) - 10)
return intel_devices; return intel_devices;
if (intel_devices) if (intel_devices)
free_sys_dev(&intel_devices); free_sys_dev(&intel_devices);
skipping to change at line 715 skipping to change at line 738
sprintf(buf, "%s/%s", dev_path, ent->d_name); sprintf(buf, "%s/%s", dev_path, ent->d_name);
rp = realpath(buf, NULL); rp = realpath(buf, NULL);
break; break;
} }
closedir(dir); closedir(dir);
return rp; return rp;
} }
char *devt_to_devpath(dev_t dev) /* Description: Return part or whole realpath for the dev
* Parameters:
* dev - the device to be quered
* dev_level - level of "/device" entries. It allows to caller to access
* virtual or physical devices which are on "path" to quered
* one.
* buf - optional, must be PATH_MAX size. If set, then will be used.
*/
char *devt_to_devpath(dev_t dev, int dev_level, char *buf)
{ {
char device[46]; char device[PATH_MAX];
char *rp; char *hw_path;
char *buf; int i;
unsigned long device_free_len = sizeof(device) - 1;
char dev_str[] = "/device";
unsigned long dev_str_len = strlen(dev_str);
sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev)); snprintf(device, sizeof(device), "/sys/dev/block/%d:%d", major(dev),
minor(dev));
rp = realpath(device, NULL); /* If caller wants block device, return path to it even if it is exposed
if (!rp) * via virtual layer.
return NULL; */
if (dev_level == 0)
return realpath(device, buf);
device_free_len -= strlen(device);
for (i = 0; i < dev_level; i++) {
if (device_free_len < dev_str_len)
return NULL;
strncat(device, dev_str, device_free_len);
buf = get_nvme_multipath_dev_hw_path(rp); /* Resolve nvme-subsystem abstraction if needed
if (buf) { */
free(rp); device_free_len -= dev_str_len;
return buf; if (i == 0) {
char rp[PATH_MAX];
if (!realpath(device, rp))
return NULL;
hw_path = get_nvme_multipath_dev_hw_path(rp);
if (hw_path) {
strcpy(device, hw_path);
device_free_len = sizeof(device) -
strlen(device) - 1;
free(hw_path);
}
}
} }
return rp; return realpath(device, buf);
} }
char *diskfd_to_devpath(int fd) char *diskfd_to_devpath(int fd, int dev_level, char *buf)
{ {
/* return the device path for a disk, return NULL on error or fd /* return the device path for a disk, return NULL on error or fd
* refers to a partition * refers to a partition
*/ */
struct stat st; struct stat st;
if (fstat(fd, &st) != 0) if (fstat(fd, &st) != 0)
return NULL; return NULL;
if (!S_ISBLK(st.st_mode)) if (!S_ISBLK(st.st_mode))
return NULL; return NULL;
return devt_to_devpath(st.st_rdev); return devt_to_devpath(st.st_rdev, dev_level, buf);
} }
int path_attached_to_hba(const char *disk_path, const char *hba_path) int path_attached_to_hba(const char *disk_path, const char *hba_path)
{ {
int rc; int rc;
if (check_env("IMSM_TEST_AHCI_DEV") || if (check_env("IMSM_TEST_AHCI_DEV") ||
check_env("IMSM_TEST_SCU_DEV")) { check_env("IMSM_TEST_SCU_DEV")) {
return 1; return 1;
} }
skipping to change at line 773 skipping to change at line 829
if (strncmp(disk_path, hba_path, strlen(hba_path)) == 0) if (strncmp(disk_path, hba_path, strlen(hba_path)) == 0)
rc = 1; rc = 1;
else else
rc = 0; rc = 0;
return rc; return rc;
} }
int devt_attached_to_hba(dev_t dev, const char *hba_path) int devt_attached_to_hba(dev_t dev, const char *hba_path)
{ {
char *disk_path = devt_to_devpath(dev); char *disk_path = devt_to_devpath(dev, 1, NULL);
int rc = path_attached_to_hba(disk_path, hba_path); int rc = path_attached_to_hba(disk_path, hba_path);
if (disk_path) if (disk_path)
free(disk_path); free(disk_path);
return rc; return rc;
} }
int disk_attached_to_hba(int fd, const char *hba_path) int disk_attached_to_hba(int fd, const char *hba_path)
{ {
char *disk_path = diskfd_to_devpath(fd); char *disk_path = diskfd_to_devpath(fd, 1, NULL);
int rc = path_attached_to_hba(disk_path, hba_path); int rc = path_attached_to_hba(disk_path, hba_path);
if (disk_path) if (disk_path)
free(disk_path); free(disk_path);
return rc; return rc;
} }
char *vmd_domain_to_controller(struct sys_dev *hba, char *buf) char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
{ {
skipping to change at line 826 skipping to change at line 882
if (strncmp(buf, hba->path, strlen(buf)) == 0) { if (strncmp(buf, hba->path, strlen(buf)) == 0) {
sprintf(path, "/sys/bus/pci/drivers/vmd/%s", ent->d_name) ; sprintf(path, "/sys/bus/pci/drivers/vmd/%s", ent->d_name) ;
closedir(dir); closedir(dir);
return realpath(path, buf); return realpath(path, buf);
} }
} }
closedir(dir); closedir(dir);
return NULL; return NULL;
} }
/* Verify that NVMe drive is supported by IMSM
/* Scan over all controller's namespaces and compare nsid value to verify if
* current one is supported. The routine doesn't check IMSM capabilities for
* namespace. Only one nvme namespace is supported by IMSM.
* Paramteres:
* fd - open descriptor to the nvme namespace
* verbose - error logging level
* Returns: * Returns:
* 0 - not supported * 1 - if namespace is supported
* 1 - supported * 0 - otherwise
*/ */
int imsm_is_nvme_supported(int disk_fd, int verbose) int imsm_is_nvme_namespace_supported(int fd, int verbose)
{ {
char nsid_path[PATH_MAX]; DIR *dir = NULL;
char buf[PATH_MAX]; struct dirent *ent;
struct stat stb; char cntrl_path[PATH_MAX];
char ns_path[PATH_MAX];
unsigned long long lowest_nsid = ULLONG_MAX;
unsigned long long this_nsid;
int rv = 0;
if (disk_fd < 0) if (!diskfd_to_devpath(fd, 1, cntrl_path) ||
return 0; !diskfd_to_devpath(fd, 0, ns_path)) {
if (verbose)
pr_err("Cannot get device paths\n");
goto abort;
}
if (fstat(disk_fd, &stb)) if (devpath_to_ll(ns_path, "nsid", &this_nsid)) {
return 0; if (verbose)
pr_err("Cannot read nsid value for %s",
basename(ns_path));
goto abort;
}
snprintf(nsid_path, PATH_MAX-1, "/sys/dev/block/%d:%d/nsid", dir = opendir(cntrl_path);
major(stb.st_rdev), minor(stb.st_rdev)); if (!dir)
goto abort;
if (load_sys(nsid_path, buf, sizeof(buf))) { /* The lowest nvme namespace is supported */
pr_err("Cannot read %s, rejecting drive\n", nsid_path); for (ent = readdir(dir); ent; ent = readdir(dir)) {
return 0; unsigned long long curr_nsid;
} char curr_ns_path[PATH_MAX + 256];
if (strtoll(buf, NULL, 10) != 1) {
if (verbose) if (!strstr(ent->d_name, "nvme"))
pr_err("Only first namespace is supported by IMSM, aborti continue;
ng\n");
return 0; snprintf(curr_ns_path, sizeof(curr_ns_path), "%s/%s",
cntrl_path, ent->d_name);
if (devpath_to_ll(curr_ns_path, "nsid", &curr_nsid))
goto abort;
if (lowest_nsid > curr_nsid)
lowest_nsid = curr_nsid;
} }
return 1;
if (this_nsid == lowest_nsid)
rv = 1;
else if (verbose)
pr_err("IMSM is supported on the lowest NVMe namespace\n");
abort:
if (dir)
closedir(dir);
return rv;
} }
/* Verify if multipath is supported by NVMe controller /* Verify if multipath is supported by NVMe controller
* Returns: * Returns:
* 0 - not supported * 0 - not supported
* 1 - supported * 1 - supported
*/ */
int is_multipath_nvme(int disk_fd) int is_multipath_nvme(int disk_fd)
{ {
char path_buf[PATH_MAX];
char ns_path[PATH_MAX]; char ns_path[PATH_MAX];
char *kname = fd2kname(disk_fd);
if (!kname)
return 0;
sprintf(path_buf, "/sys/block/%s", kname);
if (!realpath(path_buf, ns_path)) if (!diskfd_to_devpath(disk_fd, 0, ns_path))
return 0; return 0;
if (strncmp(ns_path, NVME_SUBSYS_PATH, strlen(NVME_SUBSYS_PATH)) == 0) if (strncmp(ns_path, NVME_SUBSYS_PATH, strlen(NVME_SUBSYS_PATH)) == 0)
return 1; return 1;
return 0; return 0;
} }
 End of changes. 23 change blocks. 
47 lines changed or deleted 133 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)