1
From a35ae81c6f79ab24e621a9d155538f5b88c5c2ac Mon Sep 17 00:00:00 2001
2
From: Ben Pfaff <blp@nicira.com>
3
Date: Mon, 30 Jul 2012 14:55:10 -0700
4
Subject: [PATCH 5/7] ovsdb: Do not replace symlinks by regular files during compaction.
6
Signed-off-by: Ben Pfaff <blp@nicira.com>
9
ovsdb/ovsdb-tool.c | 22 ++++++++++++++++------
10
tests/ovsdb-server.at | 15 ++++++++++++++-
11
tests/ovsdb-tool.at | 14 +++++++++++++-
12
4 files changed, 47 insertions(+), 9 deletions(-)
15
===================================================================
18
@@ -531,11 +531,14 @@ ovsdb_file_create(struct ovsdb *db, stru
20
long long int now = time_msec();
21
struct ovsdb_file *file;
25
/* Use the absolute name of the file because ovsdb-server opens its
26
* database before daemonize() chdirs to "/". */
27
- abs_name = abs_file_name(NULL, file_name);
28
+ deref_name = follow_symlinks(file_name);
29
+ abs_name = abs_file_name(NULL, deref_name);
33
return ovsdb_io_error(0, "could not determine current "
34
Index: b/ovsdb/ovsdb-tool.c
35
===================================================================
36
--- a/ovsdb/ovsdb-tool.c
37
+++ b/ovsdb/ovsdb-tool.c
40
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
41
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
43
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
45
@@ -181,16 +181,26 @@ do_create(int argc OVS_UNUSED, char *arg
49
-compact_or_convert(const char *src_name, const char *dst_name,
50
+compact_or_convert(const char *src_name_, const char *dst_name_,
51
const struct ovsdb_schema *new_schema,
54
+ char *src_name, *dst_name;
55
struct lockfile *src_lock;
56
struct lockfile *dst_lock;
57
- bool in_place = dst_name == NULL;
58
+ bool in_place = dst_name_ == NULL;
62
+ /* Dereference symlinks for source and destination names. In the in-place
63
+ * case this ensures that, if the source name is a symlink, we replace its
64
+ * target instead of replacing the symlink by a regular file. In the
65
+ * non-in-place, this has the same effect for the destination name. */
66
+ src_name = follow_symlinks(src_name_);
67
+ dst_name = (in_place
68
+ ? xasprintf("%s.tmp", src_name)
69
+ : follow_symlinks(dst_name_));
71
/* Lock the source, if we will be replacing it. */
73
retval = lockfile_lock(src_name, 0, &src_lock);
74
@@ -200,9 +210,6 @@ compact_or_convert(const char *src_name,
77
/* Get (temporary) destination and lock it. */
79
- dst_name = xasprintf("%s.tmp", src_name);
81
retval = lockfile_lock(dst_name, 0, &dst_lock);
83
ovs_fatal(retval, "%s: failed to lock lockfile", dst_name);
84
@@ -226,6 +233,9 @@ compact_or_convert(const char *src_name,
87
lockfile_unlock(dst_lock);
94
Index: b/tests/ovsdb-server.at
95
===================================================================
96
--- a/tests/ovsdb-server.at
97
+++ b/tests/ovsdb-server.at
98
@@ -254,8 +254,15 @@ AT_SETUP([compacting online])
99
AT_KEYWORDS([ovsdb server compact])
100
AT_DATA([schema], [ORDINAL_SCHEMA
103
+dnl Make sure that "ovsdb-tool create" works with a dangling symlink for
104
+dnl the database and the lockfile, creating the target of each symlink rather
105
+dnl than replacing the symlinks with regular files.
108
+ln -s dir/.db.~lock~ .db.~lock~
109
+AT_SKIP_IF([test ! -h db || test ! -h .db.~lock~])
110
AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
111
+dnl Start ovsdb-server.
112
AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --unixctl=$PWD/unixctl --remote=punix:socket --log-file=$PWD/ovsdb-server.log db], [0], [ignore], [ignore])
113
AT_CAPTURE_FILE([ovsdb-server.log])
114
dnl Do a bunch of random transactions that put crap in the database log.
115
@@ -324,6 +331,12 @@ _uuid nam
116
dnl Now compact the database in-place.
117
AT_CHECK([[ovs-appctl -t $PWD/unixctl ovsdb-server/compact]],
118
[0], [], [ignore], [test ! -e pid || kill `cat pid`])
119
+dnl Make sure that "db" is still a symlink to dir/db instead of getting
120
+dnl replaced by a regular file, ditto for .db.~lock~.
121
+AT_CHECK([test -h db])
122
+AT_CHECK([test -h .db.~lock~])
123
+AT_CHECK([test -f dir/db])
124
+AT_CHECK([test -f dir/.db.~lock~])
125
dnl We can't fully re-check the contents of the database log, because the
126
dnl order of the records is not predictable, but there should only be 4 lines
128
Index: b/tests/ovsdb-tool.at
129
===================================================================
130
--- a/tests/ovsdb-tool.at
131
+++ b/tests/ovsdb-tool.at
132
@@ -52,7 +52,14 @@ AT_SETUP([ovsdb-tool compact])
133
AT_KEYWORDS([ovsdb file positive])
134
AT_DATA([schema], [ORDINAL_SCHEMA
137
+dnl Make sure that "ovsdb-tool create" works with a dangling symlink,
138
+dnl creating the target of the symlink rather than replacing the symlink
139
+dnl with a regular file, and that the lockfile gets created relative to
140
+dnl the symlink's target.
144
+AT_SKIP_IF([test ! -h db])
145
AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
146
dnl Do a bunch of random transactions that put crap in the database log.
148
@@ -120,6 +127,11 @@ _uuid nam
149
dnl Now compact the database in-place.
151
AT_CHECK([[ovsdb-tool compact db]], [0], [], [ignore])
152
+dnl Make sure that "db" is still a symlink to dir/db instead of getting
153
+dnl replaced by a regular file.
154
+AT_CHECK([test ! -e .db.~lock])
155
+AT_CHECK([test -h db])
156
+AT_CHECK([test -f dir/db])
157
dnl We can't fully re-check the contents of the database log, because the
158
dnl order of the records is not predictable, but there should only be 4 lines