static void __rebalance2(struct dm_btree_info *info, struct btree_node *parent, struct child *l, struct child *r) { struct btree_node *left = l->n; struct btree_node *right = r->n; uint32_t nr_left = le32_to_cpu(left->header.nr_entries); uint32_t nr_right = le32_to_cpu(right->header.nr_entries); unsigned threshold = 2 * merge_threshold(left) + 1; if (nr_left + nr_right < threshold) { /* * Merge */ node_copy(left, right, -nr_right); left->header.nr_entries = cpu_to_le32(nr_left + nr_right); delete_at(parent, r->index); /* * We need to decrement the right block, but not it's * children, since they're still referenced by left. */ dm_tm_dec(info->tm, dm_block_location(r->block)); } else { /* * Rebalance. */ unsigned target_left = (nr_left + nr_right) / 2; shift(left, right, nr_left - target_left); *key_ptr(parent, r->index) = right->keys[0]; } }
static void __rebalance3(struct dm_btree_info *info, struct btree_node *parent, struct child *l, struct child *c, struct child *r) { struct btree_node *left = l->n; struct btree_node *center = c->n; struct btree_node *right = r->n; uint32_t nr_left = le32_to_cpu(left->header.nr_entries); uint32_t nr_center = le32_to_cpu(center->header.nr_entries); uint32_t nr_right = le32_to_cpu(right->header.nr_entries); unsigned threshold = merge_threshold(left) * 4 + 1; BUG_ON(left->header.max_entries != center->header.max_entries); BUG_ON(center->header.max_entries != right->header.max_entries); if ((nr_left + nr_center + nr_right) < threshold) delete_center_node(info, parent, l, c, r, left, center, right, nr_left, nr_center, nr_right); else redistribute3(info, parent, l, c, r, left, center, right, nr_left, nr_center, nr_right); }
/** * snmp_bc_set_sensor_thresholds: * @hnd: Handler data pointer. * @rid: Resource ID. * @sid: Sensor ID. * @thres: Location of sensor's settable threshold values. * * Sets sensor's threshold values. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_CAPABILITY - Resource doesn't have SAHPI_CAPABILITY_SENSOR. * SA_ERR_HPI_INVALID_CMD - Non-writable thresholds or invalid thresholds. * SA_ERR_HPI_INVALID_DATA - Threshold values out of order; negative hysteresis * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. * SA_ERR_HPI_NOT_PRESENT - Sensor doesn't exist. **/ SaErrorT snmp_bc_set_sensor_thresholds(void *hnd, SaHpiResourceIdT rid, SaHpiSensorNumT sid, const SaHpiSensorThresholdsT *thres) { SaErrorT err; SaHpiSensorThresholdsT working; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct SensorInfo *sinfo; if (!hnd || !thres) { dbg("Invalid parameter"); return(SA_ERR_HPI_INVALID_PARAMS); } /* Check if resource exists and has sensor capabilities */ SaHpiRptEntryT *rpt = oh_get_resource_by_id(handle->rptcache, rid); if (!rpt) return(SA_ERR_HPI_INVALID_RESOURCE); if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_SENSOR)) return(SA_ERR_HPI_CAPABILITY); /* Check if sensor exists and has writable thresholds */ SaHpiRdrT *rdr = oh_get_rdr_by_type(handle->rptcache, rid, SAHPI_SENSOR_RDR, sid); if (rdr == NULL) return(SA_ERR_HPI_NOT_PRESENT); sinfo = (struct SensorInfo *)oh_get_rdr_data(handle->rptcache, rid, rdr->RecordId); if (sinfo == NULL) { dbg("No sensor data. Sensor=%s", rdr->IdString.Data); return(SA_ERR_HPI_INTERNAL_ERROR); } if (rdr->RdrTypeUnion.SensorRec.Category != SAHPI_EC_THRESHOLD || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.IsAccessible == SAHPI_FALSE || rdr->RdrTypeUnion.SensorRec.ThresholdDefn.WriteThold == 0) return(SA_ERR_HPI_INVALID_CMD); /* Overlay proposed thresholds on top of existing ones and validate */ err = snmp_bc_get_sensor_thresholds(hnd, rid, sid, &working); if (err) return(err); merge_threshold(LowCritical); merge_threshold(LowMajor); merge_threshold(LowMinor); merge_threshold(UpCritical); merge_threshold(UpMajor); merge_threshold(UpMinor); merge_threshold(PosThdHysteresis); merge_threshold(NegThdHysteresis); err = oh_valid_thresholds(&working, rdr); if (err) return(err); /************************ * Write valid thresholds ************************/ write_valid_threshold(UpCritical); write_valid_threshold(UpMajor); write_valid_threshold(UpMinor); write_valid_threshold(LowCritical); write_valid_threshold(LowMajor); write_valid_threshold(LowMinor); /* We don't support writing total value hysteresis only deltas */ write_valid_threshold(NegThdHysteresis); write_valid_threshold(PosThdHysteresis); return(SA_OK); }