+ *index = vlib_buffer_pool_create (vm, (char *) name,
+ vlib_buffer_get_default_data_size (vm),
+ physmem_map_index);
+
+ if (*index == (u8) ~ 0)
+ {
+ error = clib_error_return (0, "maximum number of buffer pools reached");
+ goto done;
+ }
+
+done:
+ vec_free (name);
+ return error;
+}
+
+void
+vlib_buffer_main_alloc (vlib_main_t * vm)
+{
+ vlib_buffer_main_t *bm;
+
+ if (vm->buffer_main)
+ return;
+
+ vm->buffer_main = bm = clib_mem_alloc (sizeof (bm[0]));
+ clib_memset (vm->buffer_main, 0, sizeof (bm[0]));
+ bm->default_data_size = VLIB_BUFFER_DEFAULT_DATA_SIZE;
+}
+
+static u32
+buffer_get_cached (vlib_buffer_pool_t * bp)
+{
+ u32 cached = 0;
+ vlib_buffer_pool_thread_t *bpt;
+
+ clib_spinlock_lock (&bp->lock);
+
+ /* *INDENT-OFF* */
+ vec_foreach (bpt, bp->threads)
+ cached += bpt->n_cached;
+ /* *INDENT-ON* */
+
+ clib_spinlock_unlock (&bp->lock);
+
+ return cached;
+}
+
+static vlib_buffer_pool_t *
+buffer_get_by_index (vlib_buffer_main_t * bm, u32 index)
+{
+ vlib_buffer_pool_t *bp;
+ if (!bm->buffer_pools || vec_len (bm->buffer_pools) < index)
+ return 0;
+ bp = vec_elt_at_index (bm->buffer_pools, index);
+
+ return bp;
+}
+
+static void
+buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e, u32 index)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
+ if (!bp)
+ return;
+
+ e->value = bp->n_buffers - bp->n_avail - buffer_get_cached (bp);
+}
+
+static void
+buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e,
+ u32 index)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
+ if (!bp)
+ return;
+
+ e->value = bp->n_avail;
+}
+
+static void
+buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e, u32 index)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
+ if (!bp)
+ return;
+
+ e->value = buffer_get_cached (bp);