File: dpm_reservespace.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (131 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (8)
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
/*
 * Copyright (C) 2005-2010 by CERN/IT/GD/SC
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: dpm_reservespace.c,v $ $Revision: 3444 $ $Date: 2010-02-24 08:53:25 +0100 (Wed, 24 Feb 2010) $ CERN IT-GD/SC Jean-Philippe Baud";
#endif /* not lint */

/*	dpm_reservespace - reserve space */

#include <errno.h>
#include <string.h>
#include <sys/types.h>
#if defined(_WIN32)
#include <winsock2.h>
#else
#include <unistd.h>
#include <netinet/in.h>
#endif
#include "dpm_api.h"
#include "dpm.h"
#include "marshall.h"
#include "serrno.h"

int DLL_DECL
dpm_reservespace(const char s_type, const char *u_token, const char ret_policy, const char ac_latency, u_signed64 req_t_space, u_signed64 req_g_space, time_t req_lifetime, int nbgids, gid_t *req_gids, const char *poolname, char *actual_s_type, u_signed64 *actual_t_space, u_signed64 *actual_g_space, time_t *actual_lifetime, char *s_token)
{
	time_t actual_life;
	u_signed64 actual_space;
	char actual_type;
	int c;
	char errstring[256];
	char func[17];
	gid_t gid;
	int i;
	int msglen;
	char *p;
	char *q;
	char *rbp;
	char repbuf[4+256+25+CA_MAXDPMTOKENLEN+1];
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_reservespace");
	if (dpm_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		dpm_errmsg (func, DP053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (nbgids > 0 && ! req_gids) {
		serrno = EFAULT;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC3);
	marshall_LONG (sbp, DPM_RSVSPACE);
	q = sbp;	/* save pointer. The next field will be updated */
	msglen = 3 * LONGSIZE;
	marshall_LONG (sbp, msglen);

	/* Build request body */

	marshall_LONG (sbp, uid);
	marshall_LONG (sbp, gid);
	marshall_BYTE (sbp, s_type);
	if (u_token) {
		marshall_STRING (sbp, u_token);
	} else {
		marshall_STRING (sbp, "");
	}
	marshall_HYPER (sbp, req_t_space);
	marshall_HYPER (sbp, req_g_space);
	marshall_TIME_T (sbp, req_lifetime);
	marshall_BYTE (sbp, ret_policy);
	marshall_BYTE (sbp, ac_latency);
	marshall_LONG (sbp, nbgids > 0 ? req_gids[0] : 0);
	if (poolname) {
		marshall_STRING (sbp, poolname);
	} else {
		marshall_STRING (sbp, "");
	}
	marshall_LONG (sbp, nbgids);
	for (i = 0; i < nbgids; i++)
		marshall_LONG (sbp, req_gids[i]);

	msglen = sbp - sendbuf;
	marshall_LONG (q, msglen);	/* update length field */

	c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf), NULL, NULL);
	if (c == 0) { 
		rbp = repbuf;
		unmarshall_LONG (rbp, c);
		if (c) {
			serrno = c - DPM_FAILED;
			c = -1;
		}
		unmarshall_STRING (rbp, errstring);
		if (*errstring)
			dpm_errmsg (func, "%s\n", errstring);
		if (c == 0) {
			unmarshall_BYTE (rbp, actual_type);
		       	if (actual_s_type)
				*actual_s_type = actual_type;
			unmarshall_HYPER (rbp, actual_space);
		       	if (actual_t_space)
				*actual_t_space = actual_space;
			unmarshall_HYPER (rbp, actual_space);
		       	if (actual_g_space)
				*actual_g_space = actual_space;
			unmarshall_TIME_T (rbp, actual_life);
		       	if (actual_lifetime)
				*actual_lifetime = actual_life;
			if (s_token)
				unmarshall_STRING (rbp, s_token);
		}
	}
	return (c);
}