[Ocfs2-tools-devel] [PATCH 1/3] ocfs2_controld: Add a couple helpers for functions that retry operations
Joel Becker
joel.becker at oracle.com
Wed Apr 8 15:38:58 PDT 2009
Add a helper function to sleep for a certain number of milliseconds, and
add another function that will increase a count, printing an error
whenever that count is a power of two. eg:
retry_warning(retrycount, "Still trying to do this operation");
This increments retrycount every time it is called, but only prints the
log_error() when retrycount is a power of two.
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
ocfs2_controld/ocfs2_controld.h | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/ocfs2_controld/ocfs2_controld.h b/ocfs2_controld/ocfs2_controld.h
index 5cbb7c0..9398207 100644
--- a/ocfs2_controld/ocfs2_controld.h
+++ b/ocfs2_controld/ocfs2_controld.h
@@ -119,4 +119,36 @@ void dead_mounter(int ci, int fd);
void bail_on_mounts(void);
int send_mountgroups(int ci, int fd);
+
+/*
+ * We need to do some retries in more than one file.
+ * Here's some code that prints an error as we take a long time to do it.
+ * There is a power-of-two backoff on printing the error.
+ */
+static inline void sleep_ms(unsigned int ms)
+{
+ struct timespec ts = {
+ .tv_sec = ms / 1000,
+ .tv_nsec = (ms % 1000) * 1000,
+ };
+
+ nanosleep(&ts, NULL);
+}
+
+/* We use this for our backoff print */
+static inline unsigned int hc_hweight32(unsigned int w)
+{
+ unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
+ res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+ res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
+ res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
+ return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+}
+
+#define retry_warning(count, fmt, arg...) do { \
+ if (hc_hweight32(count) == 1) \
+ log_error(fmt, ##arg); \
+ count++; \
+} while (0)
+
#endif
--
1.6.1.3
More information about the Ocfs2-tools-devel
mailing list