Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-backend / pithos / workers / glue.py @ ead254f9

History | View | Annotate | Download (3.4 kB)

1
# -*- coding: utf-8 -
2
#
3
# Copyright 2013 GRNET S.A. All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or
6
# without modification, are permitted provided that the following
7
# conditions are met:
8
#
9
#   1. Redistributions of source code must retain the above
10
#      copyright notice, this list of conditions and the following
11
#      disclaimer.
12
#
13
#   2. Redistributions in binary form must reproduce the above
14
#      copyright notice, this list of conditions and the following
15
#      disclaimer in the documentation and/or other materials
16
#      provided with the distribution.
17
#
18
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
30
#
31
# The views and conclusions contained in the software and
32
# documentation are those of the authors and should not be
33
# interpreted as representing official policies, either expressed
34
# or implied, of GRNET S.A.
35

    
36
ARCHIPELAGO_CONF_FILE = '/etc/archipelago/archipelago.conf'
37
ARCHIPELAGO_SEGMENT_TYPE = 'segdev'
38
ARCHIPELAGO_SEGMENT_NAME = 'xsegbd'
39
CONFIG = {}
40
execfile(ARCHIPELAGO_CONF_FILE, CONFIG)
41
ARCHIPELAGO_SEGMENT_PORTS = CONFIG['SEGMENT_PORTS']
42
ARCHIPELAGO_SEGMENT_SIZE = CONFIG['SEGMENT_SIZE']
43
ARCHIPELAGO_SEGMENT_ALIGNMENT = 12
44

    
45

    
46
class WorkerGlue(object):
47

    
48
    pmap = {}
49
    worker_id = None
50
    ioctx_pool = None
51
    #glue_select = None
52

    
53
    @classmethod
54
    def setmap(cls, pid, index):
55
        WorkerGlue.pmap[pid] = index
56
        WorkerGlue.worker_id = index
57

    
58
    @classmethod
59
    def setupXsegPool(cls, ObjectPool, Segment, Xseg_ctx, pool_size=8):
60
        worker_id = WorkerGlue.worker_id
61

    
62
        class XsegPool(ObjectPool):
63

    
64
            def __init__(self):
65
                super(XsegPool, self).__init__(size=pool_size)
66
                self.segment = Segment(ARCHIPELAGO_SEGMENT_TYPE,
67
                                       ARCHIPELAGO_SEGMENT_NAME,
68
                                       ARCHIPELAGO_SEGMENT_PORTS,
69
                                       ARCHIPELAGO_SEGMENT_SIZE,
70
                                       ARCHIPELAGO_SEGMENT_ALIGNMENT)
71
                self.worker_id = worker_id
72
                self.cnt = 1
73

    
74
            def _pool_create(self):
75
                if self.worker_id == 1:
76
                    ioctx = Xseg_ctx(self.segment, self.worker_id + self.cnt)
77
                    self.cnt += 1
78
                    return ioctx
79
                else:
80
                    ioctx = Xseg_ctx(self.segment,
81
                                     (self.worker_id - 1) * pool_size + 2 +
82
                                     self.cnt)
83
                    self.cnt += 1
84
                    return ioctx
85

    
86
            def _pool_verify(self, poolobj):
87
                return True
88

    
89
            def _pool_cleanup(self, poolobj):
90
                return False
91

    
92
        WorkerGlue.ioctx_pool = XsegPool()