summary refs log tree commit diff
path: root/nixos/modules/services/network-filesystems/orangefs/server.nix
blob: 8eb754fe61103bd91674d2a74eed49a37fc556b5 (plain) (blame)
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
{ config, lib, pkgs, ...} :

with lib;

let
  cfg = config.services.orangefs.server;

  aliases = mapAttrsToList (alias: url: alias) cfg.servers;

  # Maximum handle number is 2^63
  maxHandle = 9223372036854775806;

  # One range of handles for each meta/data instance
  handleStep = maxHandle / (length aliases) / 2;

  fileSystems = mapAttrsToList (name: fs: ''
    <FileSystem>
      Name ${name}
      ID ${toString fs.id}
      RootHandle ${toString fs.rootHandle}

      ${fs.extraConfig}

      <MetaHandleRanges>
      ${concatStringsSep "\n" (
          imap0 (i: alias:
            let
              begin = i * handleStep + 3;
              end = begin + handleStep - 1;
            in "Range ${alias} ${toString begin}-${toString end}") aliases
       )}
      </MetaHandleRanges>

      <DataHandleRanges>
      ${concatStringsSep "\n" (
          imap0 (i: alias:
            let
              begin = i * handleStep + 3 + (length aliases) * handleStep;
              end = begin + handleStep - 1;
            in "Range ${alias} ${toString begin}-${toString end}") aliases
       )}
      </DataHandleRanges>

      <StorageHints>
      TroveSyncMeta ${if fs.troveSyncMeta then "yes" else "no"}
      TroveSyncData ${if fs.troveSyncData then "yes" else "no"}
      ${fs.extraStorageHints}
      </StorageHints>

    </FileSystem>
  '') cfg.fileSystems;

  configFile = ''
    <Defaults>
    LogType ${cfg.logType}
    DataStorageSpace ${cfg.dataStorageSpace}
    MetaDataStorageSpace ${cfg.metadataStorageSpace}

    BMIModules ${concatStringsSep "," cfg.BMIModules}
    ${cfg.extraDefaults}
    </Defaults>

    ${cfg.extraConfig}

    <Aliases>
    ${concatStringsSep "\n" (mapAttrsToList (alias: url: "Alias ${alias} ${url}") cfg.servers)}
    </Aliases>

    ${concatStringsSep "\n" fileSystems}
  '';

in {
  ###### interface

  options = {
    services.orangefs.server = {
      enable = mkEnableOption "OrangeFS server";

      logType = mkOption {
        type = with types; enum [ "file" "syslog" ];
        default = "syslog";
        description = "Destination for log messages.";
      };

      dataStorageSpace = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "/data/storage";
        description = "Directory for data storage.";
      };

      metadataStorageSpace = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "/data/meta";
        description = "Directory for meta data storage.";
      };

      BMIModules = mkOption {
        type = with types; listOf str;
        default = [ "bmi_tcp" ];
        example = [ "bmi_tcp" "bmi_ib"];
        description = "List of BMI modules to load.";
      };

      extraDefaults = mkOption {
        type = types.lines;
        default = "";
        description = "Extra config for <literal>&lt;Defaults&gt;</literal> section.";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = "Extra config for the global section.";
      };

      servers = mkOption {
        type = with types; attrsOf types.str;
        default = {};
        example = ''
          {
            node1="tcp://node1:3334";
            node2="tcp://node2:3334";
          }
        '';
        description = "URLs for storage server including port. The attribute names define the server alias.";
      };

      fileSystems = mkOption {
        description = ''
          These options will create the <literal>&lt;FileSystem&gt;</literal> sections of config file.
        '';
        default = { orangefs = {}; };
        defaultText = literalExample "{ orangefs = {}; }";
        example = literalExample ''
          {
            fs1 = {
              id = 101;
            };

            fs2 = {
              id = 102;
            };
          }
        '';
        type = with types; attrsOf (submodule ({ ... } : {
          options = {
            id = mkOption {
              type = types.int;
              default = 1;
              description = "File system ID (must be unique within configuration).";
            };

            rootHandle = mkOption {
              type = types.int;
              default = 3;
              description = "File system root ID.";
            };

            extraConfig = mkOption {
              type = types.lines;
              default = "";
              description = "Extra config for <literal>&lt;FileSystem&gt;</literal> section.";
            };

            troveSyncMeta = mkOption {
              type = types.bool;
              default = true;
              description = "Sync meta data.";
            };

            troveSyncData = mkOption {
              type = types.bool;
              default = false;
              description = "Sync data.";
            };

            extraStorageHints = mkOption {
              type = types.lines;
              default = "";
              description = "Extra config for <literal>&lt;StorageHints&gt;</literal> section.";
            };
          };
        }));
      };
    };
  };

  ###### implementation

  config = mkIf cfg.enable {
    environment.systemPackages = [ pkgs.orangefs ];

    # orangefs daemon will run as user
    users.users.orangefs.isSystemUser = true;
    users.groups.orangefs = {};

    # To format the file system the config file is needed.
    environment.etc."orangefs/server.conf" = {
      text = configFile;
      user = "orangefs";
      group = "orangefs";
    };

    systemd.services.orangefs-server = {
      wantedBy = [ "multi-user.target" ];
      requires = [ "network-online.target" ];
      after = [ "network-online.target" ];

      serviceConfig = {
        # Run as "simple" in forground mode.
        # This is more reliable
        ExecStart = ''
          ${pkgs.orangefs}/bin/pvfs2-server -d \
            /etc/orangefs/server.conf
        '';
        TimeoutStopSec = "120";
        User = "orangefs";
        Group = "orangefs";
      };
    };
  };

}