summaryrefslogtreecommitdiffstats
path: root/swift/1.4.8/swift.diff
blob: 0024d7b8a3a30747dec7a80b404eea7908776e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
diff --git a/setup.py b/setup.py
index d195d34..ab236ee 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 # Copyright (c) 2010-2012 OpenStack, LLC.
+# Copyright (c) 2012 Red Hat, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -94,6 +95,8 @@ setup(
             'tempurl=swift.common.middleware.tempurl:filter_factory',
             'formpost=swift.common.middleware.formpost:filter_factory',
             'name_check=swift.common.middleware.name_check:filter_factory',
+            'gluster=swift.plugins.middleware.gluster:filter_factory',
+            'glusterfs=swift.plugins.middleware.glusterfs:filter_factory',
             ],
         },
     )
diff --git a/swift/account/server.py b/swift/account/server.py
index 800b3c0..77f9879 100644
--- a/swift/account/server.py
+++ b/swift/account/server.py
@@ -1,4 +1,5 @@
 # Copyright (c) 2010-2012 OpenStack, LLC.
+# Copyright (c) 2012 Red Hat, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -35,6 +36,9 @@ from swift.common.utils import get_logger, get_param, hash_path, \
 from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
     check_mount, check_float, check_utf8
 from swift.common.db_replicator import ReplicatorRpc
+from swift.plugins.utils import plugin_enabled
+if plugin_enabled():
+    from swift.plugins.DiskDir import DiskAccount
 
 
 DATADIR = 'accounts'
@@ -52,8 +56,12 @@ class AccountController(object):
             self.mount_check, logger=self.logger)
         self.auto_create_account_prefix = \
             conf.get('auto_create_account_prefix') or '.'
+        self.fs_object = None
 
     def _get_account_broker(self, drive, part, account):
+        if self.fs_object:
+            return DiskAccount(self.root, account, self.fs_object);
+
         hsh = hash_path(account)
         db_dir = storage_directory(DATADIR, part, hsh)
         db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
@@ -153,6 +161,9 @@ class AccountController(object):
             broker.stale_reads_ok = True
         if broker.is_deleted():
             return HTTPNotFound(request=req)
+        if self.fs_object and not self.fs_object.object_only:
+            broker.list_containers_iter(None, None,None,
+                                        None, None)
         info = broker.get_info()
         headers = {
             'X-Account-Container-Count': info['container_count'],
@@ -305,8 +316,17 @@ class AccountController(object):
             broker.update_metadata(metadata)
         return HTTPNoContent(request=req)
 
+    def plugin(self, env):
+        if env.get('Gluster_enabled', False):
+            self.fs_object = env.get('fs_object')
+            self.root = env.get('root')
+            self.mount_check = False
+        else:
+            self.fs_object = None
+
     def __call__(self, env, start_response):
         start_time = time.time()
+        self.plugin(env)
         req = Request(env)
         self.logger.txn_id = req.headers.get('x-trans-id', None)
         if not check_utf8(req.path_info):
diff --git a/swift/container/server.py b/swift/container/server.py
index 8a18cfd..952b8cd 100644
--- a/swift/container/server.py
+++ b/swift/container/server.py
@@ -1,4 +1,5 @@
 # Copyright (c) 2010-2012 OpenStack, LLC.
+# Copyright (c) 2012 Red Hat, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -37,6 +38,9 @@ from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
 from swift.common.bufferedhttp import http_connect
 from swift.common.exceptions import ConnectionTimeout
 from swift.common.db_replicator import ReplicatorRpc
+from swift.plugins.utils import plugin_enabled
+if plugin_enabled():
+    from swift.plugins.DiskDir import DiskDir
 
 DATADIR = 'containers'
 
@@ -62,6 +66,7 @@ class ContainerController(object):
             ContainerBroker, self.mount_check, logger=self.logger)
         self.auto_create_account_prefix = \
             conf.get('auto_create_account_prefix') or '.'
+        self.fs_object = None
 
     def _get_container_broker(self, drive, part, account, container):
         """
@@ -73,6 +78,10 @@ class ContainerController(object):
         :param container: container name
         :returns: ContainerBroker object
         """
+        if self.fs_object:
+            return DiskDir(self.root, drive, part, account,
+                           container, self.logger,
+                           fs_object = self.fs_object)
         hsh = hash_path(account, container)
         db_dir = storage_directory(DATADIR, part, hsh)
         db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
@@ -245,6 +254,9 @@ class ContainerController(object):
         broker.stale_reads_ok = True
         if broker.is_deleted():
             return HTTPNotFound(request=req)
+        if self.fs_object and not self.fs_object.object_only:
+            broker.list_objects_iter(None, None, None, None,
+                                     None, None)
         info = broker.get_info()
         headers = {
             'X-Container-Object-Count': info['object_count'],
@@ -427,8 +439,19 @@ class ContainerController(object):
             broker.update_metadata(metadata)
         return HTTPNoContent(request=req)
 
+    def plugin(self, env):
+        if env.get('Gluster_enabled', False):
+            self.fs_object = env.get('fs_object')
+            if not self.fs_object:
+                raise NoneTypeError
+            self.root = env.get('root')
+            self.mount_check = False
+        else:
+            self.fs_object = None
+
     def __call__(self, env, start_response):
         start_time = time.time()
+        self.plugin(env)
         req = Request(env)
         self.logger.txn_id = req.headers.get('x-trans-id', None)
         if not check_utf8(req.path_info):
diff --git a/swift/obj/server.py b/swift/obj/server.py
index 9cca16b..82eaa40 100644
--- a/swift/obj/server.py
+++ b/swift/obj/server.py
@@ -1,4 +1,5 @@
 # Copyright (c) 2010-2012 OpenStack, LLC.
+# Copyright (c) 2012 Red Hat, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -45,6 +46,10 @@ from swift.common.exceptions import ConnectionTimeout, DiskFileError, \
     DiskFileNotExist
 from swift.obj.replicator import tpooled_get_hashes, invalidate_hash, \
     quarantine_renamer
+from swift.plugins.utils import plugin_enabled
+if plugin_enabled():
+    from swift.plugins.utils import X_TYPE, X_OBJECT_TYPE, FILE, DIR, MARKER_DIR, \
+         OBJECT, DIR_TYPE, FILE_TYPE
 
 
 DATADIR = 'objects'
@@ -340,6 +345,9 @@ class DiskFile(object):
         raise DiskFileNotExist('Data File does not exist.')
 
 
+if plugin_enabled():
+    from swift.plugins.DiskFile import Gluster_DiskFile
+
 class ObjectController(object):
     """Implements the WSGI application for the Swift Object Server."""
 
@@ -377,6 +385,17 @@ class ObjectController(object):
             'expiring_objects'
         self.expiring_objects_container_divisor = \
             int(conf.get('expiring_objects_container_divisor') or 86400)
+        self.fs_object = None
+
+    def get_DiskFile_obj(self, path, device, partition, account, container, obj,
+                         logger, keep_data_fp=False, disk_chunk_size=65536):
+        if self.fs_object:
+            return Gluster_DiskFile(path, device, partition, account, container,
+                            obj, logger, keep_data_fp,
+                            disk_chunk_size, fs_object = self.fs_object);
+        else:
+            return DiskFile(path, device, partition, account, container,
+                            obj, logger, keep_data_fp, disk_chunk_size)
 
     def async_update(self, op, account, container, obj, host, partition,
                      contdevice, headers_out, objdevice):
@@ -493,7 +512,7 @@ class ObjectController(object):
                                   content_type='text/plain')
         if self.mount_check and not check_mount(self.devices, device):
             return Response(status='507 %s is not mounted' % device)
-        file = DiskFile(self.devices, device, partition, account, container,
+        file = self.get_DiskFile_obj(self.devices, device, partition, account, container,
                         obj, self.logger, disk_chunk_size=self.disk_chunk_size)
 
         if 'X-Delete-At' in file.metadata and \
@@ -548,7 +567,7 @@ class ObjectController(object):
         if new_delete_at and new_delete_at < time.time():
             return HTTPBadRequest(body='X-Delete-At in past', request=request,
                                   content_type='text/plain')
-        file = DiskFile(self.devices, device, partition, account, container,
+        file = self.get_DiskFile_obj(self.devices, device, partition, account, container,
                         obj, self.logger, disk_chunk_size=self.disk_chunk_size)
         orig_timestamp = file.metadata.get('X-Timestamp')
         upload_expiration = time.time() + self.max_upload_time
@@ -580,12 +599,26 @@ class ObjectController(object):
             if 'etag' in request.headers and \
                             request.headers['etag'].lower() != etag:
                 return HTTPUnprocessableEntity(request=request)
-            metadata = {
-                'X-Timestamp': request.headers['x-timestamp'],
-                'Content-Type': request.headers['content-type'],
-                'ETag': etag,
-                'Content-Length': str(os.fstat(fd).st_size),
-            }
+            content_type = request.headers['content-type']
+            if self.fs_object and not content_type:
+                content_type = FILE_TYPE
+            if not self.fs_object:
+                metadata = {
+                    'X-Timestamp': request.headers['x-timestamp'],
+                    'Content-Type': content_type,
+                    'ETag': etag,
+                    'Content-Length': str(os.fstat(fd).st_size),
+                }
+            else:
+                x_object_type = MARKER_DIR if content_type.lower() == DIR_TYPE else FILE
+                metadata = {
+                    'X-Timestamp': request.headers['x-timestamp'],
+                    'Content-Type': content_type,
+                    'ETag': etag,
+                    'Content-Length': str(os.fstat(fd).st_size),
+                    X_TYPE: OBJECT,
+                    X_OBJECT_TYPE: x_object_type,
+                }
             metadata.update(val for val in request.headers.iteritems()
                     if val[0].lower().startswith('x-object-meta-') and
                     len(val[0]) > 14)
@@ -612,7 +645,7 @@ class ObjectController(object):
                  'x-timestamp': file.metadata['X-Timestamp'],
                  'x-etag': file.metadata['ETag'],
                  'x-trans-id': request.headers.get('x-trans-id', '-')},
-                device)
+                (self.fs_object and account) or device)
         resp = HTTPCreated(request=request, etag=etag)
         return resp
 
@@ -626,9 +659,9 @@ class ObjectController(object):
                         content_type='text/plain')
         if self.mount_check and not check_mount(self.devices, device):
             return Response(status='507 %s is not mounted' % device)
-        file = DiskFile(self.devices, device, partition, account, container,
-                        obj, self.logger, keep_data_fp=True,
-                        disk_chunk_size=self.disk_chunk_size)
+        file = self.get_DiskFile_obj(self.devices, device, partition, account, container,
+                             obj, self.logger, keep_data_fp=True,
+                             disk_chunk_size=self.disk_chunk_size)
         if file.is_deleted() or ('X-Delete-At' in file.metadata and
                 int(file.metadata['X-Delete-At']) <= time.time()):
             if request.headers.get('if-match') == '*':
@@ -702,7 +735,7 @@ class ObjectController(object):
             return resp
         if self.mount_check and not check_mount(self.devices, device):
             return Response(status='507 %s is not mounted' % device)
-        file = DiskFile(self.devices, device, partition, account, container,
+        file = self.get_DiskFile_obj(self.devices, device, partition, account, container,
                         obj, self.logger, disk_chunk_size=self.disk_chunk_size)
         if file.is_deleted() or ('X-Delete-At' in file.metadata and
                 int(file.metadata['X-Delete-At']) <= time.time()):
@@ -744,7 +777,7 @@ class ObjectController(object):
         if self.mount_check and not check_mount(self.devices, device):
             return Response(status='507 %s is not mounted' % device)
         response_class = HTTPNoContent
-        file = DiskFile(self.devices, device, partition, account, container,
+        file = self.get_DiskFile_obj(self.devices, device, partition, account, container,
                         obj, self.logger, disk_chunk_size=self.disk_chunk_size)
         if 'x-if-delete-at' in request.headers and \
                 int(request.headers['x-if-delete-at']) != \
@@ -797,9 +830,18 @@ class ObjectController(object):
             raise hashes
         return Response(body=pickle.dumps(hashes))
 
+    def plugin(self, env):
+        if env.get('Gluster_enabled', False):
+            self.fs_object = env.get('fs_object')
+            self.devices = env.get('root')
+            self.mount_check = False
+        else:
+            self.fs_object = None
+
     def __call__(self, env, start_response):
         """WSGI Application entry point for the Swift Object Server."""
         start_time = time.time()
+        self.plugin(env)
         req = Request(env)
         self.logger.txn_id = req.headers.get('x-trans-id', None)
         if not check_utf8(req.path_info):