Exemple #1
0
dm_plugin_error_t
dm_pm_indicator_execute(const char *action)
{
	dm_plugin_t *dmpip;
	char *protocol = extract_protocol(action); /* memory allocated here */
	char *actionp = extract_action(action);
	dm_plugin_action_handle_impl_t *hip;

	dmpip = protocol_to_dm_plugin(protocol);
	dstrfree(protocol);

	if (dmpip != NULL) {

		if ((hip = lookup_handle_by_action(actionp)) == NULL) {
			if (bind_action_handle(dmpip, actionp,
			    (dm_plugin_action_handle_t *)&hip) != DMPE_SUCCESS)
				return (DMPE_FAILURE);
		}

		dm_assert(dmpip->state == DMPS_INITED);
		if (dmpip->ops->indicator_execute)
			return (dmpip->ops->indicator_execute(hip->handle));
	}

	return (DMPE_FAILURE);
}
Exemple #2
0
dm_plugin_error_t
dm_pm_update_fru(const char *action, dm_fru_t *frup)
{
	char *protocol = extract_protocol(action);	/* mem alloced here */
	char *actionp = extract_action(action);
	dm_plugin_t *dmpip;

	if (protocol == NULL) {
		log_warn("FRU update: Invalid protocol specified in action "
		    "`%s'\n", action);
		return (DMPE_FAILURE);
	}

	dmpip = protocol_to_dm_plugin(protocol);
	dstrfree(protocol);

	if (dmpip != NULL) {
		dm_assert(dmpip->state == DMPS_INITED);
		if (dmpip->ops->indicator_fru_update)
			return (dmpip->ops->indicator_fru_update(actionp,
			    frup));
	}

	return (DMPE_FAILURE);
}
Exemple #3
0
static void
free_action_handle(dm_plugin_action_handle_impl_t **hipp)
{
	dm_plugin_action_handle_impl_t *hip = *hipp;
	dm_plugin_t *dmpip;

	if (hip) {
		if (hip->actionString)
			dstrfree(hip->actionString);

		dmpip = hip->plugin;

		if (dmpip->state == DMPS_INITED &&
		    dmpip->ops->indicator_free_handle)
			if (dmpip->ops->indicator_free_handle(&hip->handle)
			    != DMPE_SUCCESS) {
				log_warn("indicator_free_handle failed for %s"
				    " plugin\n",
				    dmpip->protocol);
			}

		dfree(hip, sizeof (dm_plugin_action_handle_impl_t));
		*hipp = NULL;
	}
}
Exemple #4
0
static void
free_dm_plugin(dm_plugin_t **dmpipp)
{
	dm_plugin_t *dmpip = *dmpipp;
	dm_plugin_error_t ec;

	if (dmpip) {
		if (dmpip->state == DMPS_INITED && dmpip->ops->_fini) {
			ec = dmpip->ops->_fini();
			if (ec != DMPE_SUCCESS) {
				log_warn("_fini failed for plugin %s.\n",
				    dmpip->protocol);
			}
		}

		unload_dm_plugin(dmpip);

		if (dmpip->protocol)
			dstrfree(dmpip->protocol);

		dmpip->state = DMPS_NONE;
		dmpip->ops = NULL;

		dfree(dmpip, sizeof (dm_plugin_t));
		*dmpipp = NULL;
	}
}
Exemple #5
0
size_t dstrfcatn(dstring_t dest, FILE *fp, size_t n) {

   size_t    count;  /* number of characters successfully read from fp */
   dstring_t temp;   /* will store the string which will be appended to dest */

   int olddstrerrno; /* saves dstrerrno value from call to dstrfreadn() */

   /* allocate space for our temporary string */
   if (DSTR_SUCCESS != dstrnalloc(&temp, dstrlen(dest))) {
      /* 0 items are successfully read if we can't get the memory ;)
         dstrerrno should have been set by dstralloc() */
      return 0;
   }

   /* read a line of input from the file, and make sure dstrerrno will be
      set properly */
   count = dstrfreadn(temp, fp, n);
   if (DSTR_SUCCESS != dstrerrno) {
      if (0 == dstrlen(temp)) {
         dstrfree(&temp);
         return 0;
      }
   }

   /* save dstrerrno value at this point, so that any file read errors
      will be reported */
   olddstrerrno = dstrerrno;

   /* cat temp to dest - dstrcat will see if dest is initialized for us :) */
   dstrcat(dest, temp);
   if (DSTR_SUCCESS != dstrerrno) {
      dstrfree(&temp);
      return 0;
   }

   /* free our temp string and return successfully */
   dstrfree(&temp);
   _setdstrerrno(olddstrerrno);
   return count;
}
Exemple #6
0
///
/// FreeSignatureList
void FreeSignatureList(struct MinList *signatureList)
{
  struct SignatureNode *sn;
  struct SignatureNode *next;

  ENTER();

  // we have to free the signatureList
  SafeIterateList(signatureList, struct SignatureNode *, sn, next)
  {
    dstrfree(sn->signature);
    FreeSysObject(ASOT_NODE, sn);
  }
Exemple #7
0
/*ARGSUSED*/
int
update_configuration_from_topo(fmd_hdl_t *hdl, diskmon_t *diskp)
{
	int err;
	topo_hdl_t *thp;
	topo_walk_t *twp;
	walk_diskmon_t wd;

	if ((thp = fmd_hdl_topo_hold(hdl, TOPO_VERSION)) == NULL) {
		return (TOPO_OPEN_ERROR);
	}

	wd.target = diskp;
	wd.pfmri = NULL;
	if ((twp = topo_walk_init(thp, FM_FMRI_SCHEME_HC, gather_topo_cfg,
	    &wd, &err)) == NULL) {
		fmd_hdl_topo_rele(hdl, thp);
		return (err ? TOPO_WALK_INIT_ERROR : TOPO_SUCCESS);
	}

	if (topo_walk_step(twp, TOPO_WALK_CHILD) == TOPO_WALK_ERR) {

		topo_walk_fini(twp);
		if (wd.pfmri != NULL)
			dstrfree(wd.pfmri);

		fmd_hdl_topo_rele(hdl, thp);
		return (TOPO_WALK_ERROR);
	}

	topo_walk_fini(twp);
	fmd_hdl_topo_rele(hdl, thp);
	if (wd.pfmri != NULL)
		dstrfree(wd.pfmri);

	return (TOPO_SUCCESS);
}
Exemple #8
0
/// GetFolderInfo()
// this function creates a folder string and returns it
static void GetFolderInfo(struct Data *data, struct Folder *folder)
{
  char *src;
  char *info = NULL;

  ENTER();

  // Lets create the label of the AppIcon now
  for(src = C->InfoBarText; *src; src++)
  {
    char dst[10];

    if(*src == '%')
    {
      switch(*++src)
      {
        case '%': dst[0] = '%'; dst[1] = '\0'; break;
        case 'n': snprintf(dst, sizeof(dst), "%d", folder->New);     break;
        case 'u': snprintf(dst, sizeof(dst), "%d", folder->Unread);  break;
        case 't': snprintf(dst, sizeof(dst), "%d", folder->Total);   break;
        case 's': snprintf(dst, sizeof(dst), "%d", folder->Sent);    break;
      }
    }
    else
    {
      dst[0] = *src;
      dst[1] = '\0';
    }

    dstrcat(&info, dst);
  }

  if(info != NULL)
  {
    strlcpy(data->folderInfo, info, sizeof(data->folderInfo));
    dstrfree(info);
  }
  else
    data->folderInfo[0] = '\0';


  LEAVE();
}
Exemple #9
0
static int
topo_add_bay(topo_hdl_t *thp, tnode_t *node, walk_diskmon_t *wdp)
{
	diskmon_t *target_diskp = wdp->target;
	nvlist_t	*nvlp = find_disk_monitor_private_pgroup(node);
	nvlist_t	*prop_nvlp;
	nvpair_t	*nvp = NULL;
	char		*prop_name, *prop_value;
#define	PNAME_MAX 128
	char		pname[PNAME_MAX];
	char		msgbuf[MAX_CONF_MSG_LEN];
	char		*indicator_name, *indicator_action;
	char		*indrule_states, *indrule_actions;
	int		err = 0, i;
	conf_err_t	conferr;
	boolean_t	conf_failure = B_FALSE;
	char		*unadj_physid = NULL;
	char		physid[MAXPATHLEN];
	char		*label;
	nvlist_t	*diskprops = NULL;
	char		*cstr = NULL;
	indicator_t	*indp = NULL;
	indrule_t	*indrp = NULL;
	void		*p;
	diskmon_t	*diskp;
	void		*ptr;

	/* No private properties -- just ignore the port */
	if (nvlp == NULL)
		return (0);

	/*
	 * Look for a diskmon based on this node's FMRI string.
	 * Once a diskmon has been created, it's not re-created.  This is
	 * essential for the times when the tree-walk is called after a
	 * disk is inserted (or removed) -- in that case, the disk node
	 * handler simply updates the FRU information in the diskmon.
	 */
	if ((p = fmri2ptr(thp, node, &cstr, &err)) != NULL) {

		diskp = (diskmon_t *)p;

		/*
		 * Delete the FRU information from the diskmon.  If a disk
		 * is connected, its FRU information will be refreshed by
		 * the disk node code.
		 */
		if (diskp->frup && (target_diskp == NULL ||
		    diskp == target_diskp)) {
			dm_assert(pthread_mutex_lock(&diskp->fru_mutex) == 0);
			dmfru_free(diskp->frup);
			diskp->frup = NULL;
			dm_assert(pthread_mutex_unlock(&diskp->fru_mutex) == 0);
		}

		wdp->pfmri = cstr;
		nvlist_free(nvlp);
		return (0);
	}

	/*
	 * Determine the physical path to the attachment point
	 */
	if (topo_prop_get_string(node, TOPO_PGROUP_IO,
	    TOPO_IO_AP_PATH, &unadj_physid, &err) == 0) {

		adjust_dynamic_ap(unadj_physid, physid);
		topo_hdl_strfree(thp, unadj_physid);
	} else {

		/* unadj_physid cannot have been allocated */
		if (cstr)
			dstrfree(cstr);
		nvlist_free(nvlp);
		return (-1);
	}

	/*
	 */

	/*
	 * Process the properties.  If we encounter a property that
	 * is not an indicator name, action, or rule, add it to the
	 * disk's props list.
	 */

	/* Process indicators */
	i = 0;
	indicator_name = NULL;
	indicator_action = NULL;
	do {
		if (indicator_name != NULL && indicator_action != NULL) {

			if (topoprop_indicator_add(&indp, indicator_name,
			    indicator_action) != 0) {

				conf_failure = B_TRUE;
			}

			topo_hdl_strfree(thp, indicator_name);
			topo_hdl_strfree(thp, indicator_action);
		}

		(void) snprintf(pname, PNAME_MAX, BAY_IND_NAME "-%d", i);
		if (topo_prop_get_string(node, DISK_MONITOR_PROPERTIES,
		    pname, &indicator_name, &err) != 0)
			break;

		(void) snprintf(pname, PNAME_MAX, BAY_IND_ACTION "-%d", i);
		if (topo_prop_get_string(node, DISK_MONITOR_PROPERTIES,
		    pname, &indicator_action, &err) != 0)
			break;

		i++;
	} while (!conf_failure && indicator_name != NULL &&
	    indicator_action != NULL);

	if (!conf_failure && indp != NULL &&
	    (conferr = check_inds(indp)) != E_NO_ERROR) {
		conf_error_msg(conferr, msgbuf, MAX_CONF_MSG_LEN, NULL);
		log_msg(MM_CONF, "%s: Not adding disk to list\n", msgbuf);
		conf_failure = B_TRUE;
	}

	/* Process state rules and indicator actions */
	i = 0;
	indrule_states = NULL;
	indrule_actions = NULL;
	do {
		if (indrule_states != NULL && indrule_actions != NULL) {

			if (topoprop_indrule_add(&indrp, indrule_states,
			    indrule_actions) != 0) {

				conf_failure = B_TRUE;
			}

			topo_hdl_strfree(thp, indrule_states);
			topo_hdl_strfree(thp, indrule_actions);
		}

		(void) snprintf(pname, PNAME_MAX, BAY_INDRULE_STATES "-%d", i);
		if (topo_prop_get_string(node, DISK_MONITOR_PROPERTIES,
		    pname, &indrule_states, &err) != 0)
			break;

		(void) snprintf(pname, PNAME_MAX, BAY_INDRULE_ACTIONS "-%d",
		    i);
		if (topo_prop_get_string(node, DISK_MONITOR_PROPERTIES,
		    pname, &indrule_actions, &err) != 0)
			break;

		i++;
	} while (!conf_failure && indrule_states != NULL &&
	    indrule_actions != NULL);

	if (!conf_failure && indrp != NULL && indp != NULL &&
	    ((conferr = check_indrules(indrp, (state_transition_t **)&ptr))
	    != E_NO_ERROR ||
	    (conferr = check_consistent_ind_indrules(indp, indrp,
	    (ind_action_t **)&ptr)) != E_NO_ERROR)) {

		conf_error_msg(conferr, msgbuf, MAX_CONF_MSG_LEN, ptr);
		log_msg(MM_CONF, "%s: Not adding disk to list\n", msgbuf);
		conf_failure = B_TRUE;

	}

	/*
	 * Now collect miscellaneous properties.
	 * Each property is stored as an embedded nvlist named
	 * TOPO_PROP_VAL.  The property name is stored in the value for
	 * key=TOPO_PROP_VAL_NAME and the property's value is
	 * stored in the value for key=TOPO_PROP_VAL_VAL.  This is all
	 * necessary so we can subtractively decode the properties that
	 * we do not directly handle (so that these properties are added to
	 * the per-disk properties nvlist), increasing flexibility.
	 */
	(void) nvlist_alloc(&diskprops, NV_UNIQUE_NAME, 0);
	while ((nvp = nvlist_next_nvpair(nvlp, nvp)) != NULL) {
		/* Only care about embedded nvlists named TOPO_PROP_VAL */
		if (nvpair_type(nvp) != DATA_TYPE_NVLIST ||
		    strcmp(nvpair_name(nvp), TOPO_PROP_VAL) != 0 ||
		    nvpair_value_nvlist(nvp, &prop_nvlp) != 0)
			continue;

		if (nonunique_nvlist_lookup_string(prop_nvlp,
		    TOPO_PROP_VAL_NAME, &prop_name) != 0)
			continue;

		/* Filter out indicator properties */
		if (strstr(prop_name, BAY_IND_NAME) != NULL ||
		    strstr(prop_name, BAY_IND_ACTION) != NULL ||
		    strstr(prop_name, BAY_INDRULE_STATES) != NULL ||
		    strstr(prop_name, BAY_INDRULE_ACTIONS) != NULL)
			continue;

		if (nonunique_nvlist_lookup_string(prop_nvlp, TOPO_PROP_VAL_VAL,
		    &prop_value) != 0)
			continue;

		/* Add the property to the disk's prop list: */
		if (nvlist_add_string(diskprops, prop_name, prop_value) != 0)
			log_msg(MM_TOPO,
			    "Could not add disk property `%s' with "
			    "value `%s'\n", prop_name, prop_value);
	}

	nvlist_free(nvlp);

	if (cstr != NULL) {
		namevalpr_t nvpr;
		nvlist_t *dmap_nvl;

		nvpr.name = DISK_AP_PROP_APID;
		nvpr.value = strncmp(physid, "/devices", 8) == 0 ?
		    (physid + 8) : physid;

		/*
		 * Set the diskmon's location to the value in this port's label.
		 * If there's a disk plugged in, the location will be updated
		 * to be the disk label (e.g. HD_ID_00).  Until a disk is
		 * inserted, though, there won't be a disk libtopo node
		 * created.
		 */

		/* Pass physid without the leading "/devices": */
		dmap_nvl = namevalpr_to_nvlist(&nvpr);

		diskp = new_diskmon(dmap_nvl, indp, indrp, diskprops);

		if (topo_node_label(node, &label, &err) == 0) {
			diskp->location = dstrdup(label);
			topo_hdl_strfree(thp, label);
		} else
			diskp->location = dstrdup("unknown location");

		if (!conf_failure && diskp != NULL) {
			/* Add this diskmon to the disk list */
			cfgdata_add_diskmon(config_data, diskp);
			if (nvlist_add_uint64(g_topo2diskmon, cstr,
			    (uint64_t)(uintptr_t)diskp) != 0) {
				log_msg(MM_TOPO,
				    "Could not add pointer to nvlist "
				    "for `%s'!\n", cstr);
			}
		} else if (diskp != NULL) {
			diskmon_free(diskp);
		} else {
			if (dmap_nvl)
				nvlist_free(dmap_nvl);
			if (indp)
				ind_free(indp);
			if (indrp)
				indrule_free(indrp);
			if (diskprops)
				nvlist_free(diskprops);
		}

		wdp->pfmri = cstr;
	}


	return (0);
}
Exemple #10
0
static int
topo_add_disk(topo_hdl_t *thp, tnode_t *node, walk_diskmon_t *wdp)
{
	diskmon_t *target_diskp = wdp->target;
	char		*devpath = NULL;
	char		*capacity = NULL;
	char		*firmrev = NULL;
	char		*serial = NULL;
	char		*manuf = NULL;
	char		*model = NULL;
	char		*label;
	uint64_t	ptr = 0;
	int		err;
	dm_fru_t	*frup;
	diskmon_t	*diskp;

	if (wdp->pfmri == NULL) {
		log_msg(MM_TOPO, "No diskmon for parent of node %p.\n", node);
		return (0);
	}

	if (nvlist_lookup_uint64(g_topo2diskmon, wdp->pfmri, &ptr) != 0) {
		log_msg(MM_TOPO, "No diskmon for %s: parent of node %p.\n",
		    wdp->pfmri, node);
		dstrfree(wdp->pfmri);
		/* Skip this disk: */
		return (0);
	}

	dstrfree(wdp->pfmri);
	wdp->pfmri = NULL;

	diskp = (diskmon_t *)(uintptr_t)ptr;

	/* If we were called upon to update a particular disk, do it */
	if (target_diskp != NULL && diskp != target_diskp) {
		return (0);
	}

	/*
	 * Update the diskmon's location field with the disk's label
	 */
	if (diskp->location)
		dstrfree(diskp->location);
	if (topo_node_label(node, &label, &err) == 0) {
		diskp->location = dstrdup(label);
		topo_hdl_strfree(thp, label);
	} else
		diskp->location = dstrdup("unknown location");

	/*
	 * Check for a device path property (if the disk is configured,
	 * it will be present) and add it to the diskmon's properties)
	 */
	if (topo_prop_get_string(node, TOPO_PGROUP_IO, TOPO_IO_DEV_PATH,
	    &devpath, &err) == 0) {
		char devp[PATH_MAX];
		/*
		 * Consumers of the DISK_PROP_DEVPATH property expect a raw
		 * minor device node
		 */
		(void) snprintf(devp, PATH_MAX, "%s:q,raw", devpath);
		(void) nvlist_add_string(diskp->props, DISK_PROP_DEVPATH,
		    devp);
		topo_hdl_strfree(thp, devpath);
	}

	/*
	 * Add the logical disk node, if it exists
	 */
	if (topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_LOGICAL_DISK_NAME, &devpath, &err) == 0) {
		(void) nvlist_add_string(diskp->props, DISK_PROP_LOGNAME,
		    devpath);
		topo_hdl_strfree(thp, devpath);
	}

	/*
	 * Add the FRU information (if present in the node) to the diskmon's
	 * fru data structure:
	 */
	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_MODEL, &model, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_MANUFACTURER, &manuf, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_SERIAL_NUM, &serial, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_FIRMWARE_REV, &firmrev, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_CAPACITY, &capacity, &err);

	frup = new_dmfru(manuf, model, firmrev, serial,
	    capacity == NULL ? 0 : strtoull(capacity, 0, 0));

	if (model)
		topo_hdl_strfree(thp, model);
	if (manuf)
		topo_hdl_strfree(thp, manuf);
	if (serial)
		topo_hdl_strfree(thp, serial);
	if (firmrev)
		topo_hdl_strfree(thp, firmrev);
	if (capacity)
		topo_hdl_strfree(thp, capacity);

	/* Add the fru information to the diskmon: */
	dm_assert(pthread_mutex_lock(&diskp->fru_mutex) == 0);
	dm_assert(diskp->frup == NULL);
	diskp->frup = frup;
	dm_assert(pthread_mutex_unlock(&diskp->fru_mutex) == 0);

	return (0);
}
Exemple #11
0
size_t dstrfreadl(dstring_t dest, FILE *fp) {

   char     *start;                 /* points to beginning of buffer */
   char     *bufpos;                /* our current position in DSTRBUF(dest) */
   char     *status;                /* tests for NULL when we encounter EOF */
   ptrdiff_t bufcount = 0;          /* how many characters we've read so far */

   dstring_t temp;                  /* temporary dstring_t object */

   /* make sure dest is initialized */
   if (NULL == dest) {
      _setdstrerrno(DSTR_UNINITIALIZED);
      return 0;
   }

   /* make sure fp is an opened file */
   if (NULL == fp) {
      _setdstrerrno(DSTR_UNOPENED_FILE);
      return 0;
   }

   /* allocate space for temp */
   if (DSTR_SUCCESS != dstrnalloc(&temp, dstrallocsize(dest))) {
      return 0;
   }

   bufpos = start = DSTRBUF(temp);

   /* *start = '\0'; */

   /* loop until we've read a whole line */
   while (1) {

      status = fgets(bufpos, DSTRBUFLEN(temp) - bufcount, fp);

      /* EOF or read error encountered */
      if (status == NULL) {

         /* if we read something, we should keep it */
         if (dstrlen(temp) > 0) {
            break;
         }

         /* there's nothing to read */
         if (feof(fp)) {
            _setdstrerrno(DSTR_EOF);
         } else {
            _setdstrerrno(DSTR_FILE_ERROR);
         }

         dstrfree(&temp);
         return 0;
      }

      /* make sure bufpos points to our current position */
      bufpos = start + dstrlen(temp);

      /* we're done */
      if ('\n' == bufpos[-1]) {
         break;
      }

      /* if we can't get more memory, we can't finish the line */
      if (DSTR_SUCCESS != dstrealloc(&temp, DSTRBUFLEN(temp) * 2)) {
         dstrfree(&temp);
         return 0;
      }

      /* make sure you update start, lest you suffer the wrath of glibc... */
      start = DSTRBUF(temp);
      bufpos = start + dstrlen(temp);

      /* the +1 at the end is to make sure the '\0' is counted */
      bufcount = bufpos - start + 1;
   }

   /* copy our new string into dest only if we read something */
   if (dstrlen(temp) > 0) {
      /* does dest need more space than it already has? */
      if (DSTRBUFLEN(dest) < dstrlen(temp) + 1) {
         if (DSTR_SUCCESS != dstrealloc(&dest, dstrlen(temp) + 1)) {
            dstrfree(&temp);
            return 0;
         }
      }
      dstrcpy(dest, temp);
      if (DSTR_SUCCESS != dstrerrno) {
         dstrfree(&temp);
         return 0;
      }
   }

   /* indicate success and return */
   _setdstrerrno(DSTR_SUCCESS);
   dstrfree(&temp);
   return dstrlen(dest);
}
Exemple #12
0
static int
topo_add_disk(topo_hdl_t *thp, tnode_t *node, diskmon_t *target_diskp)
{
	nvlist_t	*fmri = NULL;
	nvlist_t	*asru_fmri;
	nvlist_t	*fru_fmri;
	char		*devpath = NULL;
	char		*capacity = NULL;
	char		*firmrev = NULL;
	char		*serial = NULL;
	char		*manuf = NULL;
	char		*model = NULL;
	char		*cstr = NULL;
	char		*buf;
	char		*label;
	char		*p;
	uint64_t	ptr = 0;
	int		buflen;
	int		err;
	int		orig_cstr_len;
	dm_fru_t	*frup;
	diskmon_t	*diskp;

	/*
	 * Match this node to a disk in the configuration by looking at
	 * our parent's fmri (and do that by getting our FMRI and chopping
	 * off the last part).
	 */
	if (topo_node_resource(node, &fmri, &err) != 0) {
		log_msg(MM_TOPO, "topo_add_disk: Could not generate FMRI for "
		    "node %p!\n", (void *)node);
		return (-1);
	}

	if (topo_fmri_nvl2str(thp, fmri, &cstr, &err) != 0) {
		log_msg(MM_TOPO, "topo_add_disk: Could not create string for "
		    "node %p's FMRI!\n", (void *)node);
		nvlist_free(fmri);
		return (-1);
	}

	nvlist_free(fmri);

	/*
	 * Chop off all but last path (since there's no way to get
	 * the node's parent in the libtopo API).
	 */
	orig_cstr_len = strlen(cstr) + 1;
	p = strrchr(cstr, '/');
	dm_assert(p != NULL);
	*p = 0;
	if (nvlist_lookup_uint64(g_topo2diskmon, cstr, &ptr) != 0) {
		log_msg(MM_TOPO, "No diskmon for parent of node %p.\n", node);
		topo_hdl_free(thp, cstr, orig_cstr_len);
		/* Skip this disk: */
		return (0);
	}

	topo_hdl_free(thp, cstr, orig_cstr_len);

	diskp = (diskmon_t *)(uintptr_t)ptr;

	/* If we were called upon to update a particular disk, do it */
	if (target_diskp != NULL && diskp != target_diskp) {
		return (0);
	}

	/*
	 * Update the diskmon's ASRU and FRU with our information (this
	 * information is cached in the diskmon so we don't have to do a
	 * time-consuming topo traversal when we get an ereport).
	 */
	if (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU,
	    &asru_fmri, &err) == 0) {
		diskmon_add_asru(diskp, asru_fmri);
		nvlist_free(asru_fmri);
	}
	if (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
	    &fru_fmri, &err) == 0) {
		diskmon_add_fru(diskp, fru_fmri);
		nvlist_free(fru_fmri);
	}
	if (topo_node_resource(node, &fmri, &err) == 0) {
		diskmon_add_disk_fmri(diskp, fmri);
		nvlist_free(fmri);
	}

	/*
	 * Update the diskmon's location field with the disk's label
	 */
	if (diskp->location)
		dstrfree(diskp->location);
	if (topo_node_label(node, &label, &err) == 0) {
		diskp->location = dstrdup(label);
		topo_hdl_strfree(thp, label);
	} else
		diskp->location = dstrdup("unknown location");

	/*
	 * Check for a device path property (if the disk is configured,
	 * it will be present) and add it to the diskmon's properties)
	 */
	if (topo_prop_get_string(node, TOPO_PGROUP_IO, TOPO_IO_DEV_PATH,
	    &devpath, &err) == 0) {
		char devp[PATH_MAX];
		/*
		 * Consumers of the DISK_PROP_DEVPATH property expect a raw
		 * minor device node
		 */
		(void) snprintf(devp, PATH_MAX, "%s:q,raw", devpath);
		(void) nvlist_add_string(diskp->props, DISK_PROP_DEVPATH,
		    devp);
		topo_hdl_strfree(thp, devpath);
	}

	/*
	 * Add the logical disk node, if it exists
	 */
	if (topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_LOGICAL_DISK_NAME, &devpath, &err) == 0) {
		(void) nvlist_add_string(diskp->props, DISK_PROP_LOGNAME,
		    devpath);
		topo_hdl_strfree(thp, devpath);
	}

	/*
	 * Add the FRU information (if present in the node) to the diskmon's
	 * fru data structure:
	 */
	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_MODEL, &model, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_MANUFACTURER, &manuf, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_SERIAL_NUM, &serial, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_FIRMWARE_REV, &firmrev, &err);

	(void) topo_prop_get_string(node, TOPO_STORAGE_PGROUP,
	    TOPO_STORAGE_CAPACITY, &capacity, &err);

	frup = new_dmfru(manuf, model, firmrev, serial,
	    capacity == NULL ? 0 : strtoull(capacity, 0, 0));

	/*
	 * Update the disk's resource FMRI with the
	 * SunService-required members:
	 * FM_FMRI_HC_SERIAL_ID, FM_FMRI_HC_PART, and
	 * FM_FMRI_HC_REVISION
	 */
	(void) nvlist_add_string(diskp->disk_res_fmri,
	    FM_FMRI_HC_SERIAL_ID, serial);

	transform_model_string(manuf, model, &buf, &buflen);

	(void) nvlist_add_string(diskp->disk_res_fmri,
	    FM_FMRI_HC_PART, buf);

	/*
	 * Add the serial number to the ASRU so that when the resource
	 * is marked faulty in the fmd resource cache, the hc scheme
	 * plugin can detect when the disk is no longer installed (and so,
	 * can clear the faulty state automatically across fmd restarts).
	 *
	 * The serial number is only updated when a disk comes online
	 * because that's when the disk node exists in the topo tree.
	 * It's ok to keep a stale value in the ASRU when the disk is removed
	 * because it's only used as part of fault creation when the disk
	 * is configured (online), at which point it will be updated with
	 * the (current) serial number of the disk inserted.
	 */
	(void) nvlist_add_string(diskp->asru_fmri,
	    FM_FMRI_HC_SERIAL_ID, serial);

	dfree(buf, buflen);

	(void) nvlist_add_string(diskp->disk_res_fmri,
	    FM_FMRI_HC_REVISION, firmrev);

	if (model) {
		topo_hdl_strfree(thp, model);
	}

	if (manuf) {
		topo_hdl_strfree(thp, manuf);
	}

	if (serial) {
		topo_hdl_strfree(thp, serial);
	}

	if (firmrev) {
		topo_hdl_strfree(thp, firmrev);
	}

	if (capacity) {
		topo_hdl_strfree(thp, capacity);
	}

	/* Add the fru information to the diskmon: */
	dm_assert(pthread_mutex_lock(&diskp->fru_mutex) == 0);
	dm_assert(diskp->frup == NULL);
	diskp->frup = frup;
	dm_assert(pthread_mutex_unlock(&diskp->fru_mutex) == 0);

	return (0);
}
Exemple #13
0
/**
 * Free a printf directive.
 */
static void free_directive(struct bfs_printf *directive) {
	if (directive) {
		dstrfree(directive->str);
		free(directive);
	}
}
Exemple #14
0
void rx_addredit(UNUSED struct RexxHost *host, struct RexxParams *params, enum RexxAction action, UNUSED struct RexxMsg *rexxmsg)
{
  struct args *args = params->args;

  ENTER();

  switch(action)
  {
    case RXIF_INIT:
    {
      params->args = AllocVecPooled(G->SharedMemPool, sizeof(*args));
    }
    break;

    case RXIF_ACTION:
    {
      struct ABookNode *abn;

      abn = G->abook.arexxABN;
      if(abn == NULL && G->ABookWinObject != NULL)
        abn = (struct ABookNode *)xget(G->ABookWinObject, MUIA_AddressBookWindow_ActiveEntry);

      SHOWVALUE(DBF_ABOOK, abn);
      if(abn != NULL)
      {
        if(args->alias != NULL)
          strlcpy(abn->Alias, args->alias, sizeof(abn->Alias));
        if(args->name != NULL)
          strlcpy(abn->RealName, args->name, sizeof(abn->RealName));
        if(args->email != NULL)
          strlcpy(abn->Address, args->email, sizeof(abn->Address));
        if(args->pgp != NULL)
          strlcpy(abn->PGPId, args->pgp, sizeof(abn->PGPId));
        if(args->homepage != NULL)
          strlcpy(abn->Homepage, args->homepage, sizeof(abn->Homepage));
        if(args->street != NULL)
          strlcpy(abn->Street, args->street, sizeof(abn->Street));
        if(args->city != NULL)
          strlcpy(abn->City, args->city, sizeof(abn->City));
        if(args->country != NULL)
          strlcpy(abn->Country, args->country, sizeof(abn->Country));
        if(args->phone != NULL)
          strlcpy(abn->Phone, args->phone, sizeof(abn->Phone));
        if(args->comment != NULL)
          strlcpy(abn->Comment, args->comment, sizeof(abn->Comment));

        if(args->birthdate != NULL)
        {
          char dateStr[SIZE_SMALL];

          // if the user supplied 0 as the birthdate, he wants to "delete" the current
          // birthdate
          if(*args->birthdate == 0)
            abn->Birthday = 0;
          else if(BirthdayToString(*args->birthdate, dateStr, sizeof(dateStr)) == TRUE)
            abn->Birthday = *args->birthdate;
          else
          {
            params->rc = RETURN_ERROR;
            break;
          }
        }

        if(args->image != NULL)
          strlcpy(abn->Photo, args->image, sizeof(abn->Photo));

        if(args->member != NULL && abn->type == ABNT_LIST)
        {
          char **p;

          // free the list members in case we are told to replace them
          if(args->add == FALSE)
          {
            dstrfree(abn->ListMembers);
            abn->ListMembers = NULL;
          }

          for(p = args->member; *p != NULL; p++)
          {
            dstrcat(&abn->ListMembers, *p);
            dstrcat(&abn->ListMembers, "\n");
          }
        }

        G->abook.arexxABN = abn;
        G->abook.modified = TRUE;

        // update an existing address book window as well
        if(G->ABookWinObject != NULL)
          DoMethod(G->ABookWinObject, MUIM_AddressBookWindow_RedrawActiveEntry);
      }
      else
        params->rc = RETURN_ERROR;
    }
    break;

    case RXIF_FREE:
    {
      if(args != NULL)
        FreeVecPooled(G->SharedMemPool, args);
    }
    break;
  }

  LEAVE();
}