Beispiel #1
0
static void
get_local_iface_ids(const struct ovsrec_bridge *br_int, struct shash *lports)
{
    int i;

    for (i = 0; i < br_int->n_ports; i++) {
        const struct ovsrec_port *port_rec = br_int->ports[i];
        const char *iface_id;
        int j;

        if (!strcmp(port_rec->name, br_int->name)) {
            continue;
        }

        for (j = 0; j < port_rec->n_interfaces; j++) {
            const struct ovsrec_interface *iface_rec;

            iface_rec = port_rec->interfaces[j];
            iface_id = smap_get(&iface_rec->external_ids, "iface-id");
            if (!iface_id) {
                continue;
            }
            shash_add(lports, iface_id, iface_rec);
        }
    }
}
Beispiel #2
0
void
setMainValue (const char *pname, const char *pvalue)
{
  assert(pname);
  assert(pvalue);

  shash_add (&_mainValues, pname, pvalue);
}
Beispiel #3
0
static void
get_cpu_cores(struct shash *stats)
{
    long int n_cores = sysconf(_SC_NPROCESSORS_ONLN);
    if (n_cores > 0) {
        shash_add(stats, "cpu", xasprintf("%ld", n_cores));
    }
}
Beispiel #4
0
/** Given an array of name, value string pairs creates a new hash
    containing all of the pairs.
*/
hTab *
populateStringHash(const char **pin)
{
  hTab *pret = NULL;

  while (*pin)
    {
      shash_add (&pret, pin[0], pin[1]);
      pin += 2;
    }

  return pret;
}
Beispiel #5
0
    /* Delete zones that do not exist in above sset. */
    SIMAP_FOR_EACH_SAFE(ct_zone, ct_zone_next, ct_zones) {
        if (!sset_contains(&all_users, ct_zone->name)) {
            VLOG_DBG("removing ct zone %"PRId32" for '%s'",
                     ct_zone->data, ct_zone->name);

            struct ct_zone_pending_entry *pending = xmalloc(sizeof *pending);
            pending->state = CT_ZONE_DB_QUEUED; /* Skip flushing zone. */
            pending->zone = ct_zone->data;
            pending->add = false;
            shash_add(pending_ct_zones, ct_zone->name, pending);

            bitmap_set0(ct_zone_bitmap, ct_zone->data);
            simap_delete(ct_zones, ct_zone);
        }
    }
// create a new locl_subsystem object
static struct locl_subsystem *
add_subsystem(const struct ovsrec_subsystem *ovsrec_subsys)
{
    struct locl_subsystem *result;
    int rc;
    int idx;
    struct ovsdb_idl_txn *txn;
    struct ovsrec_temp_sensor **sensor_array;
    int sensor_idx;
    int sensor_count;
    const char *dir;
    const YamlThermalInfo *info;

    // create and initialize basic subsystem information
    VLOG_DBG("Adding new subsystem %s", ovsrec_subsys->name);
    result = (struct locl_subsystem *)malloc(sizeof(struct locl_subsystem));
    memset(result, 0, sizeof(struct locl_subsystem));
    (void)shash_add(&subsystem_data, ovsrec_subsys->name, (void *)result);
    result->name = strdup(ovsrec_subsys->name);
    result->marked = false;
    result->marked = true;
    result->parent_subsystem = NULL;  // OPS_TODO: find parent subsystem
    shash_init(&result->subsystem_sensors);

    // use a default if the hw_desc_dir has not been populated
    dir = ovsrec_subsys->hw_desc_dir;

    if (dir == NULL || strlen(dir) == 0) {
        VLOG_ERR("No h/w description directory for subsystem %s",
                                        ovsrec_subsys->name);
        return(NULL);
    }

    // since this is a new subsystem, load all of the hardware description
    // information about devices and sensors (just for this subsystem).
    // parse sensors and device data for subsystem
    rc = yaml_add_subsystem(yaml_handle, ovsrec_subsys->name, dir);

    if (rc != 0) {
        VLOG_ERR("Error reading h/w description files for subsystem %s",
                                        ovsrec_subsys->name);
        return(NULL);
    }

    // need devices data
    rc = yaml_parse_devices(yaml_handle, ovsrec_subsys->name);

    if (rc != 0) {
        VLOG_ERR("Unable to parse subsystem %s devices file (in %s)",
                                        ovsrec_subsys->name, dir);
        return(NULL);
    }

    // need thermal (sensor) data
    rc = yaml_parse_thermal(yaml_handle, ovsrec_subsys->name);

    if (rc != 0) {
        VLOG_ERR("Unable to parse subsystem %s thermal file (in %s)",
                                        ovsrec_subsys->name, dir);
        return(NULL);
    }

    // get the thermal info, need it for shutdown flag
    info = yaml_get_thermal_info(yaml_handle, ovsrec_subsys->name);
    result->emergency_shutdown = info->auto_shutdown;

    // OPS_TODO: the thermal info has a polling period, but when we
    // OPS_TODO: have multiple subsystems, that could be tricky to
    // OPS_TODO: implement if there are different polling periods.
    // OPS_TODO: For now, hardware the polling period to 5 seconds.

    // prepare to add sensors to db
    sensor_idx = 0;
    sensor_count = yaml_get_sensor_count(yaml_handle, ovsrec_subsys->name);

    if (sensor_count <= 0) {
        return(NULL);
    }

    result->valid = true;

    // subsystem db object has reference array for sensors
    sensor_array = (struct ovsrec_temp_sensor **)malloc(sensor_count * sizeof(struct ovsrec_temp_sensor *));
    memset(sensor_array, 0, sensor_count * sizeof(struct ovsrec_temp_sensor *));

    txn = ovsdb_idl_txn_create(idl);

    VLOG_DBG("There are %d sensors in subsystem %s", sensor_count, ovsrec_subsys->name);

    for (idx = 0; idx < sensor_count; idx++) {
        const YamlSensor *sensor = yaml_get_sensor(yaml_handle, ovsrec_subsys->name, idx);

        struct ovsrec_temp_sensor *ovs_sensor;
        char *sensor_name = NULL;
        struct locl_sensor *new_sensor;
        VLOG_DBG("Adding sensor %d (%s) in subsystem %s",
            sensor->number,
            sensor->location,
            ovsrec_subsys->name);

        // create a name for the sensor from the subsystem name and the
        // sensor number
        asprintf(&sensor_name, "%s-%d", ovsrec_subsys->name, sensor->number);
        // allocate and initialize basic sensor information
        new_sensor = (struct locl_sensor *)malloc(sizeof(struct locl_sensor));
        new_sensor->name = sensor_name;
        new_sensor->subsystem = result;
        new_sensor->yaml_sensor = sensor;
        new_sensor->min = 1000000;
        new_sensor->max = -1000000;
        new_sensor->temp = 0;
        new_sensor->status = SENSOR_STATUS_NORMAL;
        new_sensor->fan_speed = SENSOR_FAN_NORMAL;
        new_sensor->test_temp = -1;     // no test temperature override set

        // try to populate sensor information with real data
        tempd_read_sensor(new_sensor);

        // add sensor to subsystem sensor dictionary
        shash_add(&result->subsystem_sensors, sensor_name, (void *)new_sensor);
        // add sensor to global sensor dictionary
        shash_add(&sensor_data, sensor_name, (void *)new_sensor);

        // look for existing Temp_sensor rows
        ovs_sensor = lookup_sensor(sensor_name);

        if (ovs_sensor == NULL) {
            // existing sensor doesn't exist in db, create it
            ovs_sensor = ovsrec_temp_sensor_insert(txn);
        }

        // set initial data
        ovsrec_temp_sensor_set_name(ovs_sensor, sensor_name);
        ovsrec_temp_sensor_set_status(ovs_sensor,
            sensor_status_to_string(new_sensor->status));
        ovsrec_temp_sensor_set_temperature(ovs_sensor, new_sensor->temp);
        ovsrec_temp_sensor_set_min(ovs_sensor, new_sensor->min);
        ovsrec_temp_sensor_set_max(ovs_sensor, new_sensor->max);
        ovsrec_temp_sensor_set_fan_state(ovs_sensor,
            sensor_speed_to_string(new_sensor->fan_speed));
        ovsrec_temp_sensor_set_location(ovs_sensor, sensor->location);

        // add sensor to subsystem reference list
        sensor_array[sensor_idx++] = ovs_sensor;
    }

    ovsrec_subsystem_set_temp_sensors(ovsrec_subsys, sensor_array, sensor_count);
    // execute transaction
    ovsdb_idl_txn_commit_block(txn);
    ovsdb_idl_txn_destroy(txn);
    free(sensor_array);

    return(result);
}
Beispiel #7
0
static void
_pic14_do_link (void)
{
  /*
   * link command format:
   * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
   *
   */
#define LFRM  "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}"
  hTab *linkValues = NULL;
  char *lcmd;
  set *tSet = NULL;
  int ret;
  char * procName;

  shash_add (&linkValues, "linker", "gplink");

  /* LIBRARY SEARCH DIRS */
  mergeSets (&tSet, libPathsSet);
  mergeSets (&tSet, libDirsSet);
  shash_add (&linkValues, "incdirs", joinStrSet (processStrSet (tSet, "-I", NULL, shell_escape)));

  joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape));
  shash_add (&linkValues, "sysincdirs", joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape)));

  shash_add (&linkValues, "lflags", joinStrSet (linkOptionsSet));

  {
    char *s = shell_escape (fullDstFileName ? fullDstFileName : dstFileName);

    shash_add (&linkValues, "outfile", s);
    Safe_free (s);
  }

  if (fullSrcFileName)
    {
      struct dbuf_s dbuf;
      char *s;

      dbuf_init (&dbuf, 128);

      dbuf_append_str (&dbuf, fullDstFileName ? fullDstFileName : dstFileName);
      dbuf_append (&dbuf, ".o", 2);
      s = shell_escape (dbuf_c_str (&dbuf));
      dbuf_destroy (&dbuf);
      shash_add (&linkValues, "user_ofile", s);
      Safe_free (s);
    }

  shash_add (&linkValues, "ofiles", joinStrSet (processStrSet (relFilesSet, NULL, NULL, shell_escape)));

  /* LIBRARIES */
  procName = processor_base_name ();
  if (!procName)
    procName = "16f877";

  addSet (&libFilesSet, Safe_strdup (pic14_getPIC()->isEnhancedCore ?
          "libsdcce.lib" : "libsdcc.lib"));

    {
      struct dbuf_s dbuf;

      dbuf_init (&dbuf, 128);
      dbuf_append (&dbuf, "pic", sizeof ("pic") - 1);
      dbuf_append_str (&dbuf, procName);
      dbuf_append (&dbuf, ".lib", sizeof (".lib") - 1);
      addSet (&libFilesSet, dbuf_detach_c_str (&dbuf));
    }

  shash_add (&linkValues, "libs", joinStrSet (processStrSet (libFilesSet, NULL, NULL, shell_escape)));

  lcmd = msprintf(linkValues, LFRM);
  ret = sdcc_system (lcmd);
  Safe_free (lcmd);

  if (ret)
    exit (1);
}