"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/libglusterfs/src/generator.py" (16 Sep 2020, 25859 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "generator.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/python3
    2 
    3 import string
    4 
    5 # ops format: 'fop-arg' name type stub-field [nosync]
    6 #             'cbk-arg' name type
    7 #             'extra'   name type arg-str
    8 #             'journal' fop-type
    9 #             'link'    inode iatt
   10 #
   11 # 'role' indicates the significance of this line to the code generator (sort of
   12 # our own type).
   13 #
   14 # For fop-arg, we first need to know the name and the type of the arg so that
   15 # we can generate SHORT_ARGS (for function calls) and LONG_ARGS (for
   16 # declarations).  For code that uses stubs, we also need to know the name of
   17 # the stub field, which might be different than the argument itself.  Lastly,
   18 # for code that uses syncops, we need to know whether whoever wrote the syncop
   19 # for this fop "forgot" to include this argument.  (Editorial: this kind of
   20 # creeping inconsistency is why we should have used code generation for stubs
   21 # and syncops as well as defaults all along.)  To address this need, we use the
   22 # optional 'nosync' field for arguments (e.g. mkdir.umask) that we should skip
   23 # in generated syncop code.
   24 #
   25 # 'cbk-arg' is like fop-arg but simpler and used for generating callbacks
   26 # instead of fop functions.
   27 #
   28 # 'extra' is also like fop-arg, but it's another hack for syncops.  This time
   29 # the problem is that some of what would normally be *callback* arguments are
   30 # instead created in the caller and passed to the syncop.  We handle that by
   31 # adding an entry at the appropriate place in the fop-arg list, with the name
   32 # and type to generate a declaration and an argument string to generate the
   33 # actual syncop call.
   34 #
   35 # The mere presence of a 'journal' item is sufficient for most of the journal
   36 # code to recognize that it should do something.  However, reconciliation also
   37 # needs to decide how reconciliation builds the arguments it needs to call down
   38 # to the syncop layer, based on what's in the journal.  To do that, we divide
   39 # ops into three types and store those types in the ops table.  In general,
   40 # these three types work as follows.
   41 #
   42 #    For an fd-op, the GFID in the journal is used (in loc.gfid) field to
   43 #    look up an inode, then an anonymous fd is found/created for that inode.
   44 #
   45 #    For an inode-op, the GFID in the journal is used the same way, but no fd
   46 #    is needed.
   47 #
   48 #    For an entry-op, the *parent* GFID and name from the journal are used to
   49 #    look up an inode (via loc.pargfid and par.name respectively).
   50 #
   51 # The only places this seems to fall down is for link and create.  In link,
   52 # which is generally an entry-op, the source is looked up as though it's an
   53 # inode-op.  In create, we have an fd argument but it's really a return
   54 # argument so we get a fresh inode instead of looking one up.  Those two cases
   55 # need to be handled as special cases in the reconciliation code.
   56 #
   57 # 'link' is (hopefully) the last of the journal/syncop hacks.  Much like
   58 # 'extra', some values that are returned as callback arguments in the normal
   59 # case are handled differently for syncops.  For syncops that create objects
   60 # (e.g. mkdir) we need to link those objects into our inode table.  The 'inode'
   61 # and 'iatt' fields here give us the information we need to construct the
   62 # proper inode_link call(s).
   63 
   64 ops = {}
   65 xlator_cbks = {}
   66 xlator_dumpops = {}
   67 
   68 ops['fgetxattr'] = (
   69     ('fop-arg', 'fd',           'fd_t *'),
   70     ('fop-arg', 'name',         'const char *'),
   71     ('fop-arg', 'xdata',        'dict_t *'),
   72     ('cbk-arg', 'dict',         'dict_t *'),
   73     ('cbk-arg', 'xdata',        'dict_t *'),
   74 )
   75 
   76 ops['fsetxattr'] = (
   77     ('fop-arg', 'fd',           'fd_t *',           'fd'),
   78     ('fop-arg', 'dict',         'dict_t *',         'xattr'),
   79     ('fop-arg', 'flags',        'int32_t',          'flags'),
   80     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
   81     ('cbk-arg', 'xdata',        'dict_t *'),
   82     ('journal', 'fd-op'),
   83 )
   84 
   85 ops['setxattr'] = (
   86     ('fop-arg', 'loc',          'loc_t *',          'loc'),
   87     ('fop-arg', 'dict',         'dict_t *',         'xattr'),
   88     ('fop-arg', 'flags',        'int32_t',          'flags'),
   89     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
   90     ('cbk-arg', 'xdata',        'dict_t *'),
   91     ('journal', 'inode-op'),
   92 )
   93 
   94 ops['statfs'] = (
   95     ('fop-arg', 'loc',          'loc_t *'),
   96     ('fop-arg', 'xdata',        'dict_t *'),
   97     ('cbk-arg', 'buf',          'struct statvfs *'),
   98     ('cbk-arg', 'xdata',        'dict_t *'),
   99 )
  100 
  101 ops['fsyncdir'] = (
  102     ('fop-arg', 'fd',           'fd_t *'),
  103     ('fop-arg', 'flags',        'int32_t'),
  104     ('fop-arg', 'xdata',        'dict_t *'),
  105     ('cbk-arg', 'xdata',        'dict_t *'),
  106 )
  107 
  108 ops['opendir'] = (
  109     ('fop-arg', 'loc',          'loc_t *'),
  110     ('fop-arg', 'fd',           'fd_t *'),
  111     ('fop-arg', 'xdata',        'dict_t *'),
  112     ('cbk-arg', 'fd',           'fd_t *'),
  113     ('cbk-arg', 'xdata',        'dict_t *'),
  114 )
  115 
  116 ops['fstat'] = (
  117     ('fop-arg', 'fd',           'fd_t *'),
  118     ('fop-arg', 'xdata',        'dict_t *'),
  119     ('cbk-arg', 'buf',          'struct iatt *'),
  120     ('cbk-arg', 'xdata',        'dict_t *'),
  121 )
  122 
  123 ops['fsync'] = (
  124     ('fop-arg', 'fd',           'fd_t *'),
  125     ('fop-arg', 'flags',        'int32_t'),
  126     ('extra',   'preop',        'struct iatt',      '&preop'),
  127     ('extra',   'postop',       'struct iatt',      '&postop'),
  128     ('fop-arg', 'xdata',        'dict_t *'),
  129     ('cbk-arg', 'prebuf',       'struct iatt *'),
  130     ('cbk-arg', 'postbuf',      'struct iatt *'),
  131     ('cbk-arg', 'xdata',        'dict_t *'),
  132 )
  133 
  134 ops['flush'] = (
  135     ('fop-arg', 'fd',           'fd_t *'),
  136     ('fop-arg', 'xdata',        'dict_t *'),
  137     ('cbk-arg', 'xdata',        'dict_t *'),
  138 )
  139 
  140 ops['writev'] = (
  141     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  142     ('fop-arg', 'vector',       'struct iovec *',   'vector'),
  143     ('fop-arg', 'count',        'int32_t'),
  144     ('fop-arg', 'off',          'off_t',            'offset'),
  145     ('fop-arg', 'flags',        'uint32_t',         'flags'),
  146     ('fop-arg', 'iobref',       'struct iobref *'),
  147     ('extra',   'preop',        'struct iatt',      '&preop'),
  148     ('extra',   'postop',       'struct iatt',      '&postop'),
  149     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  150     ('cbk-arg', 'prebuf',       'struct iatt *'),
  151     ('cbk-arg', 'postbuf',      'struct iatt *'),
  152     ('cbk-arg', 'xdata',        'dict_t *'),
  153     ('journal', 'fd-op'),
  154 )
  155 
  156 ops['readv'] = (
  157     ('fop-arg', 'fd',           'fd_t *'),
  158     ('fop-arg', 'size',         'size_t'),
  159     ('fop-arg', 'offset',       'off_t'),
  160     ('fop-arg', 'flags',        'uint32_t'),
  161     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  162     ('fop-arg', 'xdata',        'dict_t *'),
  163     ('cbk-arg', 'vector',       'struct iovec *'),
  164     ('cbk-arg', 'count',        'int32_t'),
  165     ('cbk-arg', 'stbuf',        'struct iatt *'),
  166     ('cbk-arg', 'iobref',       'struct iobref *'),
  167     ('cbk-arg', 'xdata',        'dict_t *'),
  168 )
  169 
  170 ops['open'] = (
  171     ('fop-arg', 'loc',          'loc_t *'),
  172     ('fop-arg', 'flags',        'int32_t'),
  173     ('fop-arg', 'fd',           'fd_t *'),
  174     ('fop-arg', 'xdata',        'dict_t *'),
  175     ('cbk-arg', 'fd',           'fd_t *'),
  176     ('cbk-arg', 'xdata',        'dict_t *'),
  177 )
  178 
  179 ops['create'] = (
  180     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  181     ('fop-arg', 'flags',        'int32_t',          'flags'),
  182     ('fop-arg', 'mode',         'mode_t',           'mode'),
  183     ('fop-arg', 'umask',        'mode_t',           'umask',    'nosync'),
  184     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  185     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  186     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  187     ('cbk-arg', 'fd',           'fd_t *'),
  188     ('cbk-arg', 'inode',        'inode_t *'),
  189     ('cbk-arg', 'buf',          'struct iatt *'),
  190     ('cbk-arg', 'preparent',    'struct iatt *'),
  191     ('cbk-arg', 'postparent',   'struct iatt *'),
  192     ('cbk-arg', 'xdata',        'dict_t *'),
  193     ('journal', 'entry-op'),
  194     ('link',    'loc.inode',    '&iatt'),
  195 )
  196 
  197 ops['link'] = (
  198     ('fop-arg', 'oldloc',       'loc_t *',          'loc'),
  199     ('fop-arg', 'newloc',       'loc_t *',          'loc2'),
  200     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  201     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  202     ('cbk-arg', 'inode',        'inode_t *'),
  203     ('cbk-arg', 'buf',          'struct iatt *'),
  204     ('cbk-arg', 'preparent',    'struct iatt *'),
  205     ('cbk-arg', 'postparent',   'struct iatt *'),
  206     ('cbk-arg', 'xdata',        'dict_t *'),
  207     ('journal', 'entry-op'),
  208 )
  209 
  210 ops['rename'] = (
  211     ('fop-arg', 'oldloc',       'loc_t *',          'loc'),
  212     ('fop-arg', 'newloc',       'loc_t *',          'loc2'),
  213     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  214     ('cbk-arg', 'buf',          'struct iatt *'),
  215     ('cbk-arg', 'preoldparent', 'struct iatt *'),
  216     ('cbk-arg', 'postoldparent', 'struct iatt *'),
  217     ('cbk-arg', 'prenewparent', 'struct iatt *'),
  218     ('cbk-arg', 'postnewparent', 'struct iatt *'),
  219     ('cbk-arg', 'xdata',        'dict_t *'),
  220     ('journal', 'entry-op'),
  221 )
  222 
  223 ops['symlink'] = (
  224     ('fop-arg', 'linkpath',     'const char *',     'linkname'),
  225     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  226     ('fop-arg', 'umask',        'mode_t',           'mode',     'nosync'),
  227     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  228     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  229     ('cbk-arg', 'inode',        'inode_t *'),
  230     ('cbk-arg', 'buf',          'struct iatt *'),
  231     ('cbk-arg', 'preparent',    'struct iatt *'),
  232     ('cbk-arg', 'postparent',   'struct iatt *'),
  233     ('cbk-arg', 'xdata',        'dict_t *'),
  234     ('journal', 'entry-op'),
  235 )
  236 
  237 ops['rmdir'] = (
  238     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  239     ('fop-arg', 'flags',        'int32_t',          'flags'),
  240     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  241     ('cbk-arg', 'preparent',    'struct iatt *'),
  242     ('cbk-arg', 'postparent',   'struct iatt *'),
  243     ('cbk-arg', 'xdata',        'dict_t *'),
  244     ('journal', 'entry-op'),
  245 )
  246 
  247 ops['unlink'] = (
  248     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  249     ('fop-arg', 'flags',        'int32_t',          'flags',    'nosync'),
  250     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  251     ('cbk-arg', 'preparent',    'struct iatt *'),
  252     ('cbk-arg', 'postparent',   'struct iatt *'),
  253     ('cbk-arg', 'xdata',        'dict_t *'),
  254     ('journal', 'entry-op'),
  255 )
  256 
  257 ops['mkdir'] = (
  258     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  259     ('fop-arg', 'mode',         'mode_t',           'mode'),
  260     ('fop-arg', 'umask',        'mode_t',           'umask',    'nosync'),
  261     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  262     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  263     ('cbk-arg', 'inode',        'inode_t *'),
  264     ('cbk-arg', 'buf',          'struct iatt *'),
  265     ('cbk-arg', 'preparent',    'struct iatt *'),
  266     ('cbk-arg', 'postparent',   'struct iatt *'),
  267     ('cbk-arg', 'xdata',        'dict_t *'),
  268     ('journal', 'entry-op'),
  269     ('link',    'loc.inode',    '&iatt'),
  270 )
  271 
  272 ops['mknod'] = (
  273     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  274     ('fop-arg', 'mode',         'mode_t',           'mode'),
  275     ('fop-arg', 'rdev',         'dev_t',            'rdev'),
  276     ('fop-arg', 'umask',        'mode_t',           'umask',    'nosync'),
  277     ('extra',   'iatt',         'struct iatt',      '&iatt'),
  278     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  279     ('cbk-arg', 'inode',        'inode_t *'),
  280     ('cbk-arg', 'buf',          'struct iatt *'),
  281     ('cbk-arg', 'preparent',    'struct iatt *'),
  282     ('cbk-arg', 'postparent',   'struct iatt *'),
  283     ('cbk-arg', 'xdata',        'dict_t *'),
  284     ('journal', 'entry-op'),
  285 )
  286 
  287 ops['readlink'] = (
  288     ('fop-arg', 'loc',          'loc_t *'),
  289     ('fop-arg', 'size',         'size_t'),
  290     ('fop-arg', 'xdata',        'dict_t *'),
  291     ('cbk-arg', 'path',         'const char *'),
  292     ('cbk-arg', 'buf',          'struct iatt *'),
  293     ('cbk-arg', 'xdata',        'dict_t *'),
  294 )
  295 
  296 ops['access'] = (
  297     ('fop-arg', 'loc',          'loc_t *'),
  298     ('fop-arg', 'mask',         'int32_t'),
  299     ('fop-arg', 'xdata',        'dict_t *'),
  300     ('cbk-arg', 'xdata',        'dict_t *'),
  301 )
  302 
  303 ops['ftruncate'] = (
  304     ('fop-arg', 'fd',           'fd_t *',               'fd'),
  305     ('fop-arg', 'offset',       'off_t',                'offset'),
  306     ('extra',   'preop',        'struct iatt',      '&preop'),
  307     ('extra',   'postop',       'struct iatt',      '&postop'),
  308     ('fop-arg', 'xdata',        'dict_t *',             'xdata'),
  309     ('cbk-arg', 'prebuf',       'struct iatt *'),
  310     ('cbk-arg', 'postbuf',      'struct iatt *'),
  311     ('cbk-arg', 'xdata',        'dict_t *'),
  312     ('journal', 'fd-op'),
  313 )
  314 
  315 ops['getxattr'] = (
  316     ('fop-arg', 'loc',          'loc_t *'),
  317     ('fop-arg', 'name',         'const char *'),
  318     ('fop-arg', 'xdata',        'dict_t *'),
  319     ('cbk-arg', 'dict',         'dict_t *'),
  320     ('cbk-arg', 'xdata',        'dict_t *'),
  321 )
  322 
  323 ops['xattrop'] = (
  324     ('fop-arg', 'loc',          'loc_t *',              'loc'),
  325     ('fop-arg', 'flags',        'gf_xattrop_flags_t',   'optype'),
  326     ('fop-arg', 'dict',         'dict_t *',             'xattr'),
  327     ('fop-arg', 'xdata',        'dict_t *',             'xdata'),
  328     ('cbk-arg', 'dict',         'dict_t *'),
  329     ('cbk-arg', 'xdata',        'dict_t *'),
  330     ('journal', 'inode-op'),
  331 )
  332 
  333 ops['fxattrop'] = (
  334     ('fop-arg', 'fd',           'fd_t *',               'fd'),
  335     ('fop-arg', 'flags',        'gf_xattrop_flags_t',   'optype'),
  336     ('fop-arg', 'dict',         'dict_t *',             'xattr'),
  337     ('fop-arg', 'xdata',        'dict_t *',             'xdata'),
  338     ('cbk-arg', 'dict',         'dict_t *'),
  339     ('cbk-arg', 'xdata',        'dict_t *'),
  340     ('journal', 'fd-op'),
  341 )
  342 
  343 ops['removexattr'] = (
  344     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  345     ('fop-arg', 'name',         'const char *',     'name'),
  346     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  347     ('cbk-arg', 'xdata',        'dict_t *'),
  348     ('journal', 'inode-op'),
  349 )
  350 
  351 ops['fremovexattr'] = (
  352     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  353     ('fop-arg', 'name',         'const char *',     'name'),
  354     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  355     ('cbk-arg', 'xdata',        'dict_t *'),
  356     ('journal', 'fd-op'),
  357 )
  358 
  359 ops['lk'] = (
  360     ('fop-arg', 'fd',           'fd_t *'),
  361     ('fop-arg', 'cmd',          'int32_t'),
  362     ('fop-arg', 'lock',         'struct gf_flock *'),
  363     ('fop-arg', 'xdata',        'dict_t *'),
  364     ('cbk-arg', 'lock',         'struct gf_flock *'),
  365     ('cbk-arg', 'xdata',        'dict_t *'),
  366 )
  367 
  368 ops['inodelk'] = (
  369     ('fop-arg', 'volume',       'const char *'),
  370     ('fop-arg', 'loc',          'loc_t *'),
  371     ('fop-arg', 'cmd',          'int32_t'),
  372     ('fop-arg', 'lock',         'struct gf_flock *'),
  373     ('fop-arg', 'xdata',        'dict_t *'),
  374     ('cbk-arg', 'xdata',        'dict_t *'),
  375 )
  376 
  377 ops['finodelk'] = (
  378     ('fop-arg', 'volume',       'const char *'),
  379     ('fop-arg', 'fd',           'fd_t *'),
  380     ('fop-arg', 'cmd',          'int32_t'),
  381     ('fop-arg', 'lock',         'struct gf_flock *'),
  382     ('fop-arg', 'xdata',        'dict_t *'),
  383     ('cbk-arg', 'xdata',        'dict_t *'),
  384 )
  385 
  386 ops['entrylk'] = (
  387     ('fop-arg', 'volume',       'const char *'),
  388     ('fop-arg', 'loc',          'loc_t *'),
  389     ('fop-arg', 'basename',     'const char *'),
  390     ('fop-arg', 'cmd',          'entrylk_cmd'),
  391     ('fop-arg', 'type',         'entrylk_type'),
  392     ('fop-arg', 'xdata',        'dict_t *'),
  393     ('cbk-arg', 'xdata',        'dict_t *'),
  394 )
  395 
  396 ops['fentrylk'] = (
  397     ('fop-arg', 'volume',       'const char *'),
  398     ('fop-arg', 'fd',           'fd_t *'),
  399     ('fop-arg', 'basename',     'const char *'),
  400     ('fop-arg', 'cmd',          'entrylk_cmd'),
  401     ('fop-arg', 'type',         'entrylk_type'),
  402     ('fop-arg', 'xdata',        'dict_t *'),
  403     ('cbk-arg', 'xdata',        'dict_t *'),
  404 )
  405 
  406 ops['rchecksum'] = (
  407     ('fop-arg', 'fd',           'fd_t *'),
  408     ('fop-arg', 'offset',       'off_t'),
  409     ('fop-arg', 'len',          'int32_t'),
  410     ('fop-arg', 'xdata',        'dict_t *'),
  411     ('cbk-arg', 'weak_cksum',   'uint32_t'),
  412     ('cbk-arg', 'strong_cksum', 'uint8_t *'),
  413     ('cbk-arg', 'xdata',        'dict_t *'),
  414 )
  415 
  416 ops['readdir'] = (
  417     ('fop-arg', 'fd',           'fd_t *'),
  418     ('fop-arg', 'size',         'size_t'),
  419     ('fop-arg', 'off',          'off_t'),
  420     ('fop-arg', 'xdata',        'dict_t *'),
  421     ('cbk-arg', 'entries',      'gf_dirent_t *'),
  422     ('cbk-arg', 'xdata',        'dict_t *'),
  423 )
  424 
  425 ops['readdirp'] = (
  426     ('fop-arg', 'fd',           'fd_t *'),
  427     ('fop-arg', 'size',         'size_t'),
  428     ('fop-arg', 'off',          'off_t'),
  429     ('fop-arg', 'xdata',        'dict_t *'),
  430     ('cbk-arg', 'entries',      'gf_dirent_t *'),
  431     ('cbk-arg', 'xdata',        'dict_t *'),
  432 )
  433 
  434 ops['setattr'] = (
  435     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  436     ('fop-arg', 'stbuf',        'struct iatt *',    'stat'),
  437     ('fop-arg', 'valid',        'int32_t',          'valid'),
  438     ('extra',   'preop',        'struct iatt',      '&preop'),
  439     ('extra',   'postop',       'struct iatt',      '&postop'),
  440     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  441     ('cbk-arg', 'statpre',      'struct iatt *'),
  442     ('cbk-arg', 'statpost',     'struct iatt *'),
  443     ('cbk-arg', 'xdata',        'dict_t *'),
  444     ('journal', 'inode-op'),
  445 )
  446 
  447 ops['truncate'] = (
  448     ('fop-arg', 'loc',          'loc_t *',          'loc'),
  449     ('fop-arg', 'offset',       'off_t',            'offset'),
  450     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  451     ('cbk-arg', 'prebuf',       'struct iatt *'),
  452     ('cbk-arg', 'postbuf',      'struct iatt *'),
  453     ('cbk-arg', 'xdata',        'dict_t *'),
  454     ('journal', 'inode-op'),
  455 )
  456 
  457 ops['stat'] = (
  458     ('fop-arg', 'loc',          'loc_t *'),
  459     ('fop-arg', 'xdata',        'dict_t *'),
  460     ('cbk-arg', 'buf',          'struct iatt *'),
  461     ('cbk-arg', 'xdata',        'dict_t *'),
  462 )
  463 
  464 ops['lookup'] = (
  465     ('fop-arg', 'loc',          'loc_t *'),
  466     ('fop-arg', 'xdata',        'dict_t *'),
  467     ('cbk-arg', 'inode',        'inode_t *'),
  468     ('cbk-arg', 'buf',          'struct iatt *'),
  469     ('cbk-arg', 'xdata',        'dict_t *'),
  470     # We could add xdata everywhere automatically if somebody hadn't put
  471     # something after it here.
  472     ('cbk-arg', 'postparent',   'struct iatt *'),
  473 )
  474 
  475 ops['fsetattr'] = (
  476     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  477     ('fop-arg', 'stbuf',        'struct iatt *',    'stat'),
  478     ('fop-arg', 'valid',        'int32_t',          'valid'),
  479     ('extra',   'preop',        'struct iatt',      '&preop'),
  480     ('extra',   'postop',       'struct iatt',      '&postop'),
  481     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  482     ('cbk-arg', 'statpre',      'struct iatt *'),
  483     ('cbk-arg', 'statpost',     'struct iatt *'),
  484     ('cbk-arg', 'xdata',        'dict_t *'),
  485     ('journal', 'fd-op'),
  486 )
  487 
  488 ops['fallocate'] = (
  489     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  490     ('fop-arg', 'keep_size',    'int32_t',          'mode'),
  491     ('fop-arg', 'offset',       'off_t',            'offset'),
  492     ('fop-arg', 'len',          'size_t',           'size'),
  493     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  494     ('cbk-arg', 'pre',          'struct iatt *'),
  495     ('cbk-arg', 'post',         'struct iatt *'),
  496     ('cbk-arg', 'xdata',        'dict_t *'),
  497     ('journal', 'fd-op'),
  498 )
  499 
  500 ops['discard'] = (
  501     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  502     ('fop-arg', 'offset',       'off_t',            'offset'),
  503     ('fop-arg', 'len',          'size_t',           'size'),
  504     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  505     ('cbk-arg', 'pre',          'struct iatt *'),
  506     ('cbk-arg', 'post',         'struct iatt *'),
  507     ('cbk-arg', 'xdata',        'dict_t *'),
  508     ('journal', 'fd-op'),
  509 )
  510 
  511 ops['zerofill'] = (
  512     ('fop-arg', 'fd',           'fd_t *',           'fd'),
  513     ('fop-arg', 'offset',       'off_t',            'offset'),
  514     # As e.g. fallocate/discard (above) "len" should really be a size_t.
  515     ('fop-arg', 'len',          'off_t',            'size'),
  516     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  517     ('cbk-arg', 'pre',          'struct iatt *'),
  518     ('cbk-arg', 'post',         'struct iatt *'),
  519     ('cbk-arg', 'xdata',        'dict_t *'),
  520     ('journal', 'fd-op'),
  521 )
  522 
  523 ops['ipc'] = (
  524     ('fop-arg', 'op',           'int32_t'),
  525     ('fop-arg', 'xdata',        'dict_t *',         'xdata'),
  526     ('cbk-arg', 'xdata',        'dict_t *'),
  527     ('journal', 'fd-op'),
  528 )
  529 
  530 ops['seek'] = (
  531     ('fop-arg', 'fd',           'fd_t *'),
  532     ('fop-arg', 'offset',       'off_t'),
  533     ('fop-arg', 'what',         'gf_seek_what_t'),
  534     ('fop-arg', 'xdata',        'dict_t *'),
  535     ('cbk-arg', 'offset',       'off_t'),
  536     ('cbk-arg', 'xdata',        'dict_t *'),
  537 )
  538 
  539 ops['getspec'] = (
  540     ('fop-arg', 'key',          'const char *'),
  541     ('fop-arg', 'flags',        'int32_t'),
  542     ('cbk-arg', 'spec_data',    'char *'),
  543 )
  544 
  545 ops['lease'] = (
  546     ('fop-arg',     'loc',                  'loc_t *'),
  547     ('fop-arg',     'lease',                'struct gf_lease *'),
  548     ('fop-arg',     'xdata',                'dict_t *'),
  549     ('cbk-arg',     'lease',                'struct gf_lease *'),
  550     ('cbk-arg',     'xdata',                'dict_t *'),
  551 )
  552 
  553 ops['getactivelk'] = (
  554     ('fop-arg',     'loc',                  'loc_t *'),
  555     ('fop-arg',     'xdata',                'dict_t *'),
  556     ('cbk-arg',     'locklist',             'lock_migration_info_t *'),
  557     ('cbk-arg',     'xdata',                'dict_t *'),
  558 )
  559 
  560 ops['setactivelk'] = (
  561     ('fop-arg',     'loc',                  'loc_t *'),
  562     ('fop-arg',     'locklist',             'lock_migration_info_t *'),
  563     ('fop-arg',     'xdata',                'dict_t *'),
  564     ('cbk-arg',     'xdata',                'dict_t *'),
  565 )
  566 
  567 ops['put'] = (
  568     ('fop-arg',     'loc',                  'loc_t *',                      'loc'),
  569     ('fop-arg',     'mode',                 'mode_t',                       'mode'),
  570     ('fop-arg',     'umask',                'mode_t',                       'umask'),
  571     ('fop-arg',     'flags',                'uint32_t',                     'flags'),
  572     ('fop-arg',     'vector',               'struct iovec *',               'vector'),
  573     ('fop-arg',     'count',                'int32_t'),
  574     ('fop-arg',     'off',                  'off_t',                        'offset'),
  575     ('fop-arg',     'iobref',               'struct iobref *'),
  576     ('fop-arg',     'dict',                 'dict_t *',                     'xattr'),
  577     ('fop-arg',     'xdata',                'dict_t *',                     'xdata'),
  578     ('cbk-arg',     'inode',                'inode_t *'),
  579     ('cbk-arg',     'buf',                  'struct iatt *'),
  580     ('cbk-arg',     'preparent',            'struct iatt *'),
  581     ('cbk-arg',     'postparent',           'struct iatt *'),
  582     ('cbk-arg',     'xdata',                'dict_t *'),
  583 )
  584 
  585 ops['icreate'] = (
  586     ('fop-arg',     'loc',                   'loc_t *'),
  587     ('fop-arg',     'mode',                  'mode_t'),
  588     ('fop-arg',     'xdata',                 'dict_t *'),
  589     ('cbk-arg',     'inode',                 'inode_t *'),
  590     ('cbk-arg',     'buf',                   'struct iatt *'),
  591     ('cbk-arg',     'xdata',                 'dict_t *'),
  592 )
  593 
  594 ops['namelink'] = (
  595     ('fop-arg',     'loc',                   'loc_t *'),
  596     ('fop-arg',     'xdata',                 'dict_t *'),
  597     ('cbk-arg',     'prebuf',                'struct iatt *'),
  598     ('cbk-arg',     'postbuf',               'struct iatt *'),
  599     ('cbk-arg',     'xdata',                 'dict_t *'),
  600 )
  601 
  602 ops['copy_file_range'] = (
  603         ('fop-arg',     'fd_in',                 'fd_t *'),
  604         ('fop-arg',     'off_in',                'off64_t '),
  605         ('fop-arg',     'fd_out',                'fd_t *'),
  606         ('fop-arg',     'off_out',               'off64_t '),
  607         ('fop-arg',     'len',                   'size_t'),
  608         ('fop-arg',     'flags',                 'uint32_t'),
  609         ('fop-arg',     'xdata',                 'dict_t *'),
  610         ('cbk-arg',     'stbuf',                 'struct iatt *'),
  611         ('cbk-arg',     'prebuf_dst',            'struct iatt *'),
  612         ('cbk-arg',     'postbuf_dst',           'struct iatt *'),
  613         ('cbk-arg',     'xdata',                 'dict_t *'),
  614 )
  615 #####################################################################
  616 xlator_cbks['forget'] = (
  617     ('fn-arg',      'this',        'xlator_t *'),
  618     ('fn-arg',      'inode',       'inode_t *'),
  619     ('ret-val',     'int32_t',     '0'),
  620 )
  621 
  622 xlator_cbks['release'] = (
  623     ('fn-arg',      'this',        'xlator_t *'),
  624     ('fn-arg',      'fd',          'fd_t *'),
  625     ('ret-val',     'int32_t',     '0'),
  626 )
  627 
  628 xlator_cbks['releasedir'] = (
  629     ('fn-arg',      'this',        'xlator_t *'),
  630     ('fn-arg',      'fd',          'fd_t *'),
  631     ('ret-val',     'int32_t',     '0'),
  632 )
  633 
  634 xlator_cbks['invalidate'] = (
  635     ('fn-arg',      'this',        'xlator_t *'),
  636     ('fn-arg',      'inode',       'inode_t *'),
  637     ('ret-val',     'int32_t',     '0'),
  638 )
  639 
  640 xlator_cbks['client_destroy'] = (
  641     ('fn-arg',      'this',        'xlator_t *'),
  642     ('fn-arg',      'client',      'client_t *'),
  643     ('ret-val',     'int32_t',     '0'),
  644 )
  645 
  646 xlator_cbks['client_disconnect'] = (
  647     ('fn-arg',      'this',        'xlator_t *'),
  648     ('fn-arg',      'client',      'client_t *'),
  649     ('ret-val',     'int32_t',     '0'),
  650 )
  651 
  652 xlator_cbks['ictxmerge'] = (
  653     ('fn-arg',      'this',        'xlator_t *'),
  654     ('fn-arg',      'fd',          'fd_t *'),
  655     ('fn-arg',      'inode',       'inode_t *'),
  656     ('fn-arg',      'linked_inode', 'inode_t *'),
  657     ('ret-val',     'void',        ''),
  658 )
  659 
  660 #####################################################################
  661 xlator_dumpops['priv'] = (
  662     ('fn-arg',      'this',        'xlator_t *'),
  663     ('ret-val',     'int32_t',     '0'),
  664 )
  665 
  666 xlator_dumpops['inode'] = (
  667     ('fn-arg',      'this',        'xlator_t *'),
  668     ('ret-val',     'int32_t',     '0'),
  669 )
  670 
  671 xlator_dumpops['fd'] = (
  672     ('fn-arg',      'this',        'xlator_t *'),
  673     ('ret-val',     'int32_t',     '0'),
  674 )
  675 
  676 xlator_dumpops['inodectx'] = (
  677     ('fn-arg',      'this',        'xlator_t *'),
  678     ('fn-arg',      'ino',         'inode_t *'),
  679     ('ret-val',     'int32_t',     '0'),
  680 )
  681 
  682 xlator_dumpops['fdctx'] = (
  683     ('fn-arg',      'this',        'xlator_t *'),
  684     ('fn-arg',      'fd',          'fd_t *'),
  685     ('ret-val',     'int32_t',     '0'),
  686 )
  687 
  688 xlator_dumpops['priv_to_dict'] = (
  689     ('fn-arg',      'this',        'xlator_t *'),
  690     ('fn-arg',      'dict',        'dict_t *'),
  691     ('ret-val',     'int32_t',     '0'),
  692 )
  693 
  694 xlator_dumpops['inode_to_dict'] = (
  695     ('fn-arg',      'this',        'xlator_t *'),
  696     ('fn-arg',      'dict',        'dict_t *'),
  697     ('ret-val',     'int32_t',     '0'),
  698 )
  699 
  700 xlator_dumpops['fd_to_dict'] = (
  701     ('fn-arg',      'this',        'xlator_t *'),
  702     ('fn-arg',      'dict',        'dict_t *'),
  703     ('ret-val',     'int32_t',     '0'),
  704 )
  705 
  706 xlator_dumpops['inodectx_to_dict'] = (
  707     ('fn-arg',      'this',        'xlator_t *'),
  708     ('fn-arg',      'ino',         'inode_t *'),
  709     ('fn-arg',      'dict',        'dict_t *'),
  710     ('ret-val',     'int32_t',     '0'),
  711 )
  712 
  713 xlator_dumpops['fdctx_to_dict'] = (
  714     ('fn-arg',      'this',        'xlator_t *'),
  715     ('fn-arg',      'fd',          'fd_t *'),
  716     ('fn-arg',      'dict',        'dict_t *'),
  717     ('ret-val',     'int32_t',     '0'),
  718 )
  719 
  720 xlator_dumpops['history'] = (
  721     ('fn-arg',      'this',        'xlator_t *'),
  722     ('ret-val',     'int32_t',     '0'),
  723 )
  724 
  725 def get_error_arg (type_str):
  726     if type_str.find(" *") != -1:
  727         return "NULL"
  728     return "-1"
  729 
  730 def get_subs (names, types, cbktypes=None):
  731     sdict = {}
  732     sdict["@SHORT_ARGS@"] = ', '.join(names)
  733     # Convert two separate tuples to one of (name, type) sub-tuples.
  734     as_tuples = list(zip(types, names))
  735     # Convert each sub-tuple into a "type name" string.
  736     as_strings = [' '.join(item) for item in as_tuples]
  737     # Join all of those into one big string.
  738     sdict["@LONG_ARGS@"] = ',\n\t'.join(as_strings)
  739     # So much more readable than string.join(map(string.join,zip(...))))
  740     sdict["@ERROR_ARGS@"] = ', '.join(list(map(get_error_arg, types)))
  741     if cbktypes is not None:
  742         sdict["@CBK_ERROR_ARGS@"] = ', '.join(list(map(get_error_arg, cbktypes)))
  743     return sdict
  744 
  745 def generate (tmpl, name, subs):
  746     text = tmpl.replace("@NAME@", name)
  747     if name == "writev":
  748         # More spurious inconsistency.
  749         text = text.replace("@UPNAME@", "WRITE")
  750     elif name == "readv":
  751         text = text.replace("@UPNAME@", "READ")
  752     else:
  753         text = text.replace("@UPNAME@", name.upper())
  754     for old, new in subs[name].items():
  755         text = text.replace(old, new)
  756     # TBD: reindent/reformat the result for maximum readability.
  757     return text
  758 
  759 fop_subs = {}
  760 cbk_subs = {}
  761 
  762 for name, args in ops.items():
  763 
  764     # Create the necessary substitution strings for fops.
  765     arg_names = [ a[1] for a in args if a[0] == 'fop-arg']
  766     arg_types = [ a[2] for a in args if a[0] == 'fop-arg']
  767     cbk_types = [ a[2] for a in args if a[0] == 'cbk-arg']
  768     fop_subs[name] = get_subs(arg_names, arg_types, cbk_types)
  769 
  770     # Same thing for callbacks.
  771     arg_names = [ a[1] for a in args if a[0] == 'cbk-arg']
  772     arg_types = [ a[2] for a in args if a[0] == 'cbk-arg']
  773     cbk_subs[name] = get_subs(arg_names, arg_types)
  774 
  775     # Callers can add other subs to these tables, or even create their
  776     # own tables, using these same techniques, and then pass the result
  777     # to generate() which would Do The Right Thing with them.