disk_common.c (602ca9ea) | disk_common.c (940d71d2) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 23 unchanged lines hidden (view full) --- 32 * A topo_list_t of all disks is returned by a successful disk_list_gather() 33 * call, and the list is freed by a disk_list_free(). To create a 'disk' topo 34 * node below a specific 'bay' parent node either disk_declare_path() or 35 * disk_declare_addr() are called. The caller determines which 'disk' is 36 * in which 'bay'. A disk's 'label' and 'authority' information come from 37 * its parent 'bay' node. 38 */ 39 | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 23 unchanged lines hidden (view full) --- 32 * A topo_list_t of all disks is returned by a successful disk_list_gather() 33 * call, and the list is freed by a disk_list_free(). To create a 'disk' topo 34 * node below a specific 'bay' parent node either disk_declare_path() or 35 * disk_declare_addr() are called. The caller determines which 'disk' is 36 * in which 'bay'. A disk's 'label' and 'authority' information come from 37 * its parent 'bay' node. 38 */ 39 |
40#include <ctype.h> |
|
40#include <strings.h> 41#include <libdevinfo.h> 42#include <devid.h> 43#include <sys/libdevid.h> 44#include <pthread.h> 45#include <inttypes.h> 46#include <sys/dkio.h> 47#include <sys/scsi/scsi_types.h> --- 239 unchanged lines hidden (view full) --- 287 if (asru) 288 nvlist_free(asru); 289 return (err); 290 291error: err = topo_mod_seterrno(mod, err); 292 goto out; 293} 294 | 41#include <strings.h> 42#include <libdevinfo.h> 43#include <devid.h> 44#include <sys/libdevid.h> 45#include <pthread.h> 46#include <inttypes.h> 47#include <sys/dkio.h> 48#include <sys/scsi/scsi_types.h> --- 239 unchanged lines hidden (view full) --- 288 if (asru) 289 nvlist_free(asru); 290 return (err); 291 292error: err = topo_mod_seterrno(mod, err); 293 goto out; 294} 295 |
296/* 297 * Manufacturing strings can contain characters that are invalid for use in hc 298 * authority names. This trims leading and trailing whitespace, and 299 * substitutes any characters known to be bad. 300 */ 301char * 302disk_auth_clean(topo_mod_t *mod, const char *begin) 303{ 304 const char *end; 305 char *buf, *str; 306 size_t count; 307 308 if (begin == NULL) 309 return (NULL); 310 311 end = begin + strlen(begin); 312 313 while (begin < end && isspace(*begin)) 314 begin++; 315 while (begin < end && isspace(*(end - 1))) 316 end--; 317 318 count = end - begin; 319 if ((buf = topo_mod_alloc(mod, count + 1)) == NULL) 320 return (NULL); 321 322 (void) strlcpy(buf, begin, count + 1); 323 324 while ((str = strpbrk(buf, " :=")) != NULL) 325 *str = '-'; 326 327 return (buf); 328} 329 |
|
295/* create the disk topo node */ 296static tnode_t * 297disk_tnode_create(topo_mod_t *mod, tnode_t *parent, 298 disk_di_node_t *dnode, const char *name, topo_instance_t i) 299{ 300 int len; 301 nvlist_t *fmri; 302 tnode_t *dtn; 303 char *part = NULL; | 330/* create the disk topo node */ 331static tnode_t * 332disk_tnode_create(topo_mod_t *mod, tnode_t *parent, 333 disk_di_node_t *dnode, const char *name, topo_instance_t i) 334{ 335 int len; 336 nvlist_t *fmri; 337 tnode_t *dtn; 338 char *part = NULL; |
304 char *b = NULL; | |
305 nvlist_t *auth; | 339 nvlist_t *auth; |
340 char *mfg, *model, *firm, *serial; |
|
306 | 341 |
342 mfg = disk_auth_clean(mod, dnode->ddn_mfg); 343 model = disk_auth_clean(mod, dnode->ddn_model); 344 firm = disk_auth_clean(mod, dnode->ddn_firm); 345 serial = disk_auth_clean(mod, dnode->ddn_serial); 346 |
|
307 /* form 'part=' of fmri as "<mfg>-<model>" */ | 347 /* form 'part=' of fmri as "<mfg>-<model>" */ |
308 if (dnode->ddn_mfg && dnode->ddn_model) { 309 /* XXX replace first ' ' in the model with a '-' */ 310 if ((b = strchr(dnode->ddn_model, ' ')) != NULL) 311 *b = '-'; 312 len = strlen(dnode->ddn_mfg) + 1 + strlen(dnode->ddn_model) + 1; | 348 if (mfg != NULL && model != NULL) { 349 len = strlen(mfg) + 1 + strlen(model) + 1; |
313 if ((part = topo_mod_alloc(mod, len)) != NULL) 314 (void) snprintf(part, len, "%s-%s", | 350 if ((part = topo_mod_alloc(mod, len)) != NULL) 351 (void) snprintf(part, len, "%s-%s", |
315 dnode->ddn_mfg, dnode->ddn_model); | 352 mfg, model); |
316 } 317 318 auth = topo_mod_auth(mod, parent); 319 fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL, | 353 } 354 355 auth = topo_mod_auth(mod, parent); 356 fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL, |
320 auth, part ? part : dnode->ddn_model, dnode->ddn_firm, 321 dnode->ddn_serial); | 357 auth, part ? part : model, firm, serial); |
322 nvlist_free(auth); 323 | 358 nvlist_free(auth); 359 |
324 if (part && (part != dnode->ddn_model)) 325 topo_mod_free(mod, part, len); 326 else if (b) 327 *b = ' '; /* restore blank */ | 360 topo_mod_strfree(mod, part); 361 topo_mod_strfree(mod, mfg); 362 topo_mod_strfree(mod, model); 363 topo_mod_strfree(mod, firm); 364 topo_mod_strfree(mod, serial); |
328 329 if (fmri == NULL) { 330 topo_mod_dprintf(mod, "disk_tnode_create: " 331 "hcfmri (%s%d/%s%d) error %s\n", 332 topo_node_name(parent), topo_node_instance(parent), 333 name, i, topo_strerror(topo_mod_errno(mod))); 334 return (NULL); 335 } --- 533 unchanged lines hidden --- | 365 366 if (fmri == NULL) { 367 topo_mod_dprintf(mod, "disk_tnode_create: " 368 "hcfmri (%s%d/%s%d) error %s\n", 369 topo_node_name(parent), topo_node_instance(parent), 370 name, i, topo_strerror(topo_mod_errno(mod))); 371 return (NULL); 372 } --- 533 unchanged lines hidden --- |