~ubuntu-branches/ubuntu/oneiric/openafs/oneiric-201305130334

« back to all changes in this revision

Viewing changes to src/rxgen/rpc_parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2006-10-21 20:57:09 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061021205709-y5keam1v20qxjwwo
Tags: 1.4.2-2
Upstream fix to prevent butc segfaulting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <afs/param.h>
37
37
 
38
38
RCSID
39
 
    ("$Header: /cvs/openafs/src/rxgen/rpc_parse.c,v 1.18.2.1 2005/10/15 01:20:03 shadow Exp $");
 
39
    ("$Header: /cvs/openafs/src/rxgen/rpc_parse.c,v 1.18.2.3 2006/07/31 21:51:21 shadow Exp $");
40
40
 
41
41
#include <stdlib.h>
42
42
#include <stdio.h>
134
134
static void cs_ProcSendPacket_setup(definition * defp, int split_flag);
135
135
static void cs_ProcUnmarshallOutParams_setup(definition * defp);
136
136
static void cs_ProcTail_setup(definition * defp, int split_flag);
 
137
static void ucs_ProcName_setup(definition * defp, char *procheader,
 
138
                              int split_flag);
 
139
static void ucs_ProcParams_setup(definition * defp, int split_flag);
 
140
static void ucs_ProcTail_setup(definition * defp, int split_flag);
137
141
static void ss_Proc_CodeGeneration(definition * defp);
138
142
static void ss_ProcName_setup(definition * defp);
139
143
static void ss_ProcParams_setup(definition * defp, int *somefrees);
1102
1106
        }
1103
1107
        cs_ProcTail_setup(defp, split_flag);
1104
1108
    }
 
1109
 
 
1110
    if (!kflag && !split_flag && uflag) {
 
1111
        ucs_ProcName_setup(defp, "ubik_", split_flag);
 
1112
        if (!cflag) {
 
1113
            ucs_ProcParams_setup(defp, split_flag);
 
1114
            ucs_ProcTail_setup(defp, split_flag);
 
1115
        }
 
1116
    }
1105
1117
}
1106
1118
 
1107
1119
 
1730
1742
}
1731
1743
 
1732
1744
 
 
1745
static void
 
1746
ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
 
1747
{
 
1748
    proc1_list *plist;
 
1749
 
 
1750
    if (!cflag) {
 
1751
      f_print(fout, "int %s%s%s%s(aclient, aflags", procheader, prefix,
 
1752
              PackagePrefix[PackageIndex], defp->pc.proc_name);
 
1753
    }
 
1754
    if ((strlen(procheader) + strlen(prefix) +
 
1755
         strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
 
1756
        MAX_FUNCTION_NAME_LEN) {
 
1757
        error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
 
1758
    }
 
1759
    if (!cflag) {
 
1760
        for (plist = defp->pc.plists; plist; plist = plist->next) {
 
1761
            if (plist->component_kind == DEF_PARAM) {
 
1762
                plist->pl.param_flag &= ~PROCESSED_PARAM;
 
1763
                f_print(fout, ", %s", plist->pl.param_name);
 
1764
            }
 
1765
        }
 
1766
        f_print(fout, ")\n");
 
1767
    }
 
1768
}
 
1769
 
 
1770
 
 
1771
static void
 
1772
ucs_ProcParams_setup(definition * defp, int split_flag)
 
1773
{
 
1774
    proc1_list *plist, *plist1;
 
1775
 
 
1776
    f_print(fout, "\tregister struct ubik_client *aclient;\n\tafs_int32 aflags;\n");
 
1777
    for (plist = defp->pc.plists; plist; plist = plist->next) {
 
1778
        if (plist->component_kind == DEF_PARAM
 
1779
            && !(plist->pl.param_flag & PROCESSED_PARAM)) {
 
1780
            if (plist->pl.param_flag & OUT_STRING) {
 
1781
                f_print(fout, "\t%s *%s", plist->pl.param_type,
 
1782
                        plist->pl.param_name);
 
1783
            } else {
 
1784
                f_print(fout, "\t%s %s", plist->pl.param_type,
 
1785
                        plist->pl.param_name);
 
1786
            }
 
1787
            plist->pl.param_flag |= PROCESSED_PARAM;
 
1788
            for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
 
1789
                if ((plist1->component_kind == DEF_PARAM)
 
1790
                    && streq(plist->pl.param_type, plist1->pl.param_type)
 
1791
                    && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
 
1792
                    char *star = "";
 
1793
                    char *pntr = strchr(plist1->pl.param_type, '*');
 
1794
                    if (pntr)
 
1795
                        star = "*";
 
1796
                    if (plist1->pl.param_flag & OUT_STRING) {
 
1797
                        f_print(fout, ", *%s%s", star, plist1->pl.param_name);
 
1798
                    } else {
 
1799
                        f_print(fout, ", %s%s", star, plist1->pl.param_name);
 
1800
                    }
 
1801
                    plist1->pl.param_flag |= PROCESSED_PARAM;
 
1802
                }
 
1803
            }
 
1804
            f_print(fout, ";\n");
 
1805
        }
 
1806
    }
 
1807
}
 
1808
 
 
1809
static void
 
1810
ucs_ProcTail_setup(definition * defp, int split_flag)
 
1811
{
 
1812
    proc1_list *plist;
 
1813
 
 
1814
    f_print(fout, "{\tafs_int32 rcode, code, newHost, thisHost, i, _ucount;\n");
 
1815
    f_print(fout, "\tint chaseCount, pass, needsync, inlist;\n");
 
1816
#if 0 /* goes with block below */
 
1817
    f_print(fout, "\tint j;\n");
 
1818
#endif
 
1819
    f_print(fout, "\tstruct rx_connection *tc;\n");
 
1820
    f_print(fout, "\tstruct rx_peer *rxp;\n");
 
1821
    f_print(fout, "\tshort origLevel;\n\n");
 
1822
    f_print(fout, "\tif (!aclient)\n");
 
1823
    f_print(fout, "\t\treturn UNOENT;\n");
 
1824
    f_print(fout, "\tLOCK_UBIK_CLIENT(aclient);\n\n");
 
1825
    f_print(fout, "\t restart:\n");
 
1826
    f_print(fout, "\torigLevel = aclient->initializationState;\n");
 
1827
    f_print(fout, "\trcode = UNOSERVERS;\n");
 
1828
    f_print(fout, "\tchaseCount = inlist = needsync = 0;\n\n");
 
1829
#if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
 
1830
    f_print(fout, "\tLOCK_UCLNT_CACHE;\n");
 
1831
    f_print(fout, "\tfor (j = 0; ((j < SYNCCOUNT) && calls_needsync[j]); j++) {\n");
 
1832
    f_print(fout, "\t\tif (calls_needsync[j] == (int *)%s%s%s) {\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
 
1833
    f_print(fout, "\t\t\tinlist = needsync = 1;\n");
 
1834
    f_print(fout, "\t\t\tbreak;\n");
 
1835
    f_print(fout, "\t\t}\n");
 
1836
    f_print(fout, "\t}\n");
 
1837
    f_print(fout, "\tUNLOCK_UCLNT_CACHE;\n");
 
1838
#endif
 
1839
    f_print(fout, "\t/* \n\t* First  pass, we try all servers that are up.\n\t* Second pass, we try all servers.\n\t*/\n");
 
1840
    f_print(fout, "\tfor (pass = 0; pass < 2; pass++) {  /*p */\n");
 
1841
    f_print(fout, "\t\t/* For each entry in our servers list */\n");
 
1842
    f_print(fout, "\t\tfor (_ucount = 0;; _ucount++) {     /*s */\n\n");
 
1843
    f_print(fout, "\t\tif (needsync) {\n");
 
1844
    f_print(fout, "\t\t\t/* Need a sync site. Lets try to quickly find it */\n");
 
1845
    f_print(fout, "\t\t\tif (aclient->syncSite) {\n");
 
1846
    f_print(fout, "\t\t\t\tnewHost = aclient->syncSite;        /* already in network order */\n");
 
1847
    f_print(fout, "\t\t\t\taclient->syncSite = 0;      /* Will reset if it works */\n");
 
1848
    f_print(fout, "\t\t\t} else if (aclient->conns[3]) {\n");
 
1849
    f_print(fout, "\t\t\t\t/* If there are fewer than four db servers in a cell,\n");
 
1850
    f_print(fout, "\t\t\t\t* there's no point in making the GetSyncSite call.\n");
 
1851
    f_print(fout, "\t\t\t\t* At best, it's a wash. At worst, it results in more\n");
 
1852
    f_print(fout, "\t\t\t\t* RPCs than you would otherwise make.\n");
 
1853
    f_print(fout, "\t\t\t\t*/\n");
 
1854
    f_print(fout, "\t\t\t\ttc = aclient->conns[_ucount];\n");
 
1855
    f_print(fout, "\t\t\t\tif (tc && rx_ConnError(tc)) {\n");
 
1856
    f_print(fout, "\t\t\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
 
1857
    f_print(fout, "\t\t\t\t}\n");
 
1858
    f_print(fout, "\t\t\t\tif (!tc)\n");
 
1859
    f_print(fout, "\t\t\t\t\tbreak;\n");
 
1860
    f_print(fout, "\t\t\t\tcode = VOTE_GetSyncSite(tc, &newHost);\n");
 
1861
    f_print(fout, "\t\t\t\tif (aclient->initializationState != origLevel)\n");
 
1862
    f_print(fout, "\t\t\t\t\tgoto restart;   /* somebody did a ubik_ClientInit */\n");
 
1863
    f_print(fout, "\t\t\t\tif (code)\n");
 
1864
    f_print(fout, "\t\t\t\t\tnewHost = 0;\n");
 
1865
    f_print(fout, "\t\t\t\tnewHost = htonl(newHost);   /* convert to network order */\n");
 
1866
    f_print(fout, "\t\t\t} else {\n");
 
1867
    f_print(fout, "\t\t\t\tnewHost = 0;\n");
 
1868
    f_print(fout, "\t\t\t}\n");
 
1869
    f_print(fout, "\t\t\tif (newHost) {\n");
 
1870
    f_print(fout, "\t\t\t\t/* position count at the appropriate slot in the client\n");
 
1871
    f_print(fout, "\t\t\t\t* structure and retry. If we can't find in slot, we'll\n");
 
1872
    f_print(fout, "\t\t\t\t* just continue through the whole list \n");
 
1873
    f_print(fout, "\t\t\t\t*/\n");
 
1874
    f_print(fout, "\t\t\t\tfor (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {\n");
 
1875
    f_print(fout, "\t\t\t\t\trxp = rx_PeerOf(aclient->conns[i]);\n");
 
1876
    f_print(fout, "\t\t\t\t\tthisHost = rx_HostOf(rxp);\n");
 
1877
    f_print(fout, "\t\t\t\t\tif (!thisHost)\n");
 
1878
    f_print(fout, "\t\t\t\t\t\tbreak;\n");
 
1879
    f_print(fout, "\t\t\t\t\tif (thisHost == newHost) {\n");
 
1880
    f_print(fout, "\t\t\t\t\t\tif (chaseCount++ > 2)\n");
 
1881
    f_print(fout, "\t\t\t\t\t\t\tbreak;  /* avoid loop asking */\n");
 
1882
    f_print(fout, "\t\t\t\t\t\t_ucount = i;  /* this index is the sync site */\n");
 
1883
    f_print(fout, "\t\t\t\t\t\tbreak;\n");
 
1884
    f_print(fout, "\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n");
 
1885
    f_print(fout, "\t\t/*needsync */\n");
 
1886
    f_print(fout, "\t\ttc = aclient->conns[_ucount];\n");
 
1887
    f_print(fout, "\t\tif (tc && rx_ConnError(tc)) {\n");
 
1888
    f_print(fout, "\t\t\taclient->conns[_ucount] = tc = ubik_RefreshConn(tc);\n");
 
1889
    f_print(fout, "\t\t}\n");
 
1890
    f_print(fout, "\t\tif (!tc)\n");
 
1891
    f_print(fout, "\t\t\tbreak;\n\n");
 
1892
    f_print(fout, "\t\tif ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {\n");
 
1893
    f_print(fout, "\t\t\tcontinue;       /* this guy's down */\n");
 
1894
    f_print(fout, "\t\t}\n");
 
1895
    
 
1896
    f_print(fout, "\t\trcode = %s%s%s(tc\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
 
1897
    for (plist = defp->pc.plists; plist; plist = plist->next) {
 
1898
        if (plist->component_kind == DEF_PARAM) {
 
1899
            plist->pl.param_flag &= ~PROCESSED_PARAM;
 
1900
            f_print(fout, ", %s", plist->pl.param_name);
 
1901
        }
 
1902
    }
 
1903
    f_print(fout, ");\n");
 
1904
    f_print(fout, "\t\tif (aclient->initializationState != origLevel) {\n");
 
1905
    f_print(fout, "\t\t\t/* somebody did a ubik_ClientInit */\n");
 
1906
    f_print(fout, "\t\t\tif (rcode)\n");
 
1907
    f_print(fout, "\t\t\t\tgoto restart;       /* call failed */\n");
 
1908
    f_print(fout, "\t\t\telse\n");
 
1909
    f_print(fout, "\t\t\t\tgoto done;  /* call suceeded */\n");
 
1910
    f_print(fout, "\t\t}\n");
 
1911
    f_print(fout, "\t\tif (rcode < 0) {    /* network errors */\n");
 
1912
    f_print(fout, "\t\t\taclient->states[_ucount] |= CFLastFailed; /* Mark server down */\n");
 
1913
    f_print(fout, "\t\t} else if (rcode == UNOTSYNC) {\n");
 
1914
    f_print(fout, "\t\t\tneedsync = 1;\n");
 
1915
    f_print(fout, "\t\t} else if (rcode != UNOQUORUM) {\n");
 
1916
    f_print(fout, "\t\t\t/* either misc ubik code, or misc appl code, or success. */\n");
 
1917
    f_print(fout, "\t\t\taclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/\n");
 
1918
    f_print(fout, "\t\t\tgoto done;      /* all done */\n");
 
1919
    f_print(fout, "\t\t}\n");
 
1920
    f_print(fout, "\t\t}                       /*s */\n");
 
1921
    f_print(fout, "\t}                           /*p */\n\n");
 
1922
    f_print(fout, "\tdone:\n");
 
1923
    f_print(fout, "\tif (needsync) {\n");
 
1924
    f_print(fout, "\t\tif (!inlist) {          /* Remember proc call that needs sync site */\n");
 
1925
#if 0 /* We should do some sort of caching algorithm for this, but I need to think about it - shadow 26 jun 06 */
 
1926
    f_print(fout, "\t\t\tLOCK_UCLNT_CACHE;\n");
 
1927
    f_print(fout, "\t\t\tcalls_needsync[synccount % SYNCCOUNT] = (int *)%s%s%s;\n", prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
 
1928
    f_print(fout, "\t\t\tsynccount++;\n");
 
1929
    f_print(fout, "\t\t\tUNLOCK_UCLNT_CACHE;\n");
 
1930
#endif
 
1931
    f_print(fout, "\t\t\tinlist = 1;\n");
 
1932
    f_print(fout, "\t\t}\n");
 
1933
    f_print(fout, "\t\tif (!rcode) {           /* Remember the sync site - cmd successful */\n");
 
1934
    f_print(fout, "\t\t\trxp = rx_PeerOf(aclient->conns[_ucount]);\n");
 
1935
    f_print(fout, "\t\t\taclient->syncSite = rx_HostOf(rxp);\n");
 
1936
    f_print(fout, "\t\t}\n");
 
1937
    f_print(fout, "\t}\n");
 
1938
    f_print(fout, "\tUNLOCK_UBIK_CLIENT(aclient);\n");
 
1939
    f_print(fout, "\treturn rcode;\n}\n\n");
 
1940
}
 
1941
 
 
1942
 
1733
1943
static int
1734
1944
opcode_holes_exist(void)
1735
1945
{