~james-page/ubuntu/raring/openvswitch/lts-raring-backport-dkms

« back to all changes in this revision

Viewing changes to debian/patches/bug-681880-7-ovsdb-Do-not-replace-symlinks-by-regular-files-durin.patch

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-08-07 16:00:53 UTC
  • mfrom: (5.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120807160053-nj4pgmkn6bp8t4md
Tags: 1.4.2+git20120612-9ubuntu1
* Merge from Debian unstable; remaining changes:
  - d/control: Disable openvswitch-datapath-dkms package.
* Dropped changes:
  - d/patches/kernel_3.5_support.patch: Superceded by 
    bug-684057-ovs-ctl-Add-support-for-newer-module-name.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
 
 
6
Signed-off-by: Ben Pfaff <blp@nicira.com>
 
7
---
 
8
 ovsdb/file.c          |    5 ++++-
 
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(-)
 
13
 
 
14
Index: b/ovsdb/file.c
 
15
===================================================================
 
16
--- a/ovsdb/file.c
 
17
+++ b/ovsdb/file.c
 
18
@@ -531,11 +531,14 @@ ovsdb_file_create(struct ovsdb *db, stru
 
19
 {
 
20
     long long int now = time_msec();
 
21
     struct ovsdb_file *file;
 
22
+    char *deref_name;
 
23
     char *abs_name;
 
24
 
 
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);
 
30
+    free(deref_name);
 
31
     if (!abs_name) {
 
32
         *filep = NULL;
 
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
 
38
@@ -1,5 +1,5 @@
 
39
 /*
 
40
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
 
41
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
 
42
  *
 
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
 
46
 }
 
47
 
 
48
 static void
 
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,
 
52
                    const char *comment)
 
53
 {
 
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;
 
59
     struct ovsdb *db;
 
60
     int retval;
 
61
 
 
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_));
 
70
+
 
71
     /* Lock the source, if we will be replacing it. */
 
72
     if (in_place) {
 
73
         retval = lockfile_lock(src_name, 0, &src_lock);
 
74
@@ -200,9 +210,6 @@ compact_or_convert(const char *src_name,
 
75
     }
 
76
 
 
77
     /* Get (temporary) destination and lock it. */
 
78
-    if (in_place) {
 
79
-        dst_name = xasprintf("%s.tmp", src_name);
 
80
-    }
 
81
     retval = lockfile_lock(dst_name, 0, &dst_lock);
 
82
     if (retval) {
 
83
         ovs_fatal(retval, "%s: failed to lock lockfile", dst_name);
 
84
@@ -226,6 +233,9 @@ compact_or_convert(const char *src_name,
 
85
     }
 
86
 
 
87
     lockfile_unlock(dst_lock);
 
88
+
 
89
+    free(src_name);
 
90
+    free(dst_name);
 
91
 }
 
92
 
 
93
 static void
 
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
 
101
 ])
 
102
-touch .db.~lock~
 
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.
 
106
+mkdir dir
 
107
+ln -s dir/db db
 
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
 
127
 dnl in it now.
 
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
 
135
 ])
 
136
-touch .db.~lock~
 
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.
 
141
+mkdir dir
 
142
+: > dir/.db.~lock~
 
143
+ln -s dir/db db
 
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.
 
147
 AT_CHECK(
 
148
@@ -120,6 +127,11 @@ _uuid                                nam
 
149
 dnl Now compact the database in-place.
 
150
 touch .db.tmp.~lock~
 
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
 
159
 dnl in it now.