From 0063725d282616789af263d5dfccf1a107415a72 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 4 Jan 2007 03:08:16 +0000 Subject: [PATCH] Minimal hotplug support: provide a facility for notifying persistent reference holders that their reference is about to become invalid. --- src/core/hotplug.c | 45 +++++++++++++++++++++++++++++ src/include/gpxe/hotplug.h | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/core/hotplug.c create mode 100644 src/include/gpxe/hotplug.h diff --git a/src/core/hotplug.c b/src/core/hotplug.c new file mode 100644 index 00000000..0f5f4730 --- /dev/null +++ b/src/core/hotplug.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2007 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +/** @file + * + * Hotplug support + * + */ + +/** + * Forget all persistent references to an object + * + * @v list List of persistent references + */ +void forget_references ( struct list_head *list ) { + struct reference *ref; + struct reference *ref_tmp; + + list_for_each_entry_safe ( ref, ref_tmp, list, list ) { + ref->forget ( ref ); + } + + /* The list had really better be empty by now, otherwise we're + * screwed. + */ + assert ( list_empty ( list ) ); +} diff --git a/src/include/gpxe/hotplug.h b/src/include/gpxe/hotplug.h new file mode 100644 index 00000000..e6e132de --- /dev/null +++ b/src/include/gpxe/hotplug.h @@ -0,0 +1,58 @@ +#ifndef _GPXE_HOTPLUG_H +#define _GPXE_HOTPLUG_H + +/** @file + * + * Hotplug support + * + */ + +#include + +/** + * A persistent reference to another data structure + * + * This data structure should be embedded within any data structure + * (the referrer) which holds a persistent reference to a separate, + * volatile data structure (the referee). + */ +struct reference { + /** List of persistent references */ + struct list_head list; + /** Forget persistent reference + * + * @v ref Persistent reference + * + * This method is called immediately before the referred-to + * data structure is destroyed. The reference holder must + * forget all references to the referee before returning from + * this method. + * + * This method must also call ref_del() to remove the + * reference. + */ + void ( * forget ) ( struct reference *ref ); +}; + +/** + * Add persistent reference + * + * @v ref Persistent reference + * @v list List of persistent references + */ +static inline void ref_add ( struct reference *ref, struct list_head *list ) { + list_add ( &ref->list, list ); +} + +/** + * Remove persistent reference + * + * @v ref Persistent reference + */ +static inline void ref_del ( struct reference *ref ) { + list_del ( &ref->list ); +} + +extern void forget_references ( struct list_head *list ); + +#endif /* _GPXE_HOTPLUG_H */