*** empty log message ***
[arla.git] / milko / vldb / vldbserver.c
blobce7ace6438d5c0e738d1fb39b785a4448b037927
1 /*
2 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "vldb_locl.h"
36 RCSID("$Id$");
39 * The rpc - calls
42 int
43 SVL_CreateEntry(struct rx_call *call,
44 const vldbentry *newentry)
46 char *name;
47 disk_vlentry diskentry;
48 disk_vlentry tempentry;
50 mlog_log (MDEBVL, "SVL_CreateEntry (name=%s, ids=%d,%d,%d flags=%d)\n",
51 newentry->name,
52 newentry->volumeId[RWVOL],
53 newentry->volumeId[ROVOL],
54 newentry->volumeId[BACKVOL],
55 newentry->flags);
58 if (!sec_is_superuser(call))
59 return VL_PERM;
61 if ((vldb_id_to_name(newentry->volumeId[RWVOL], &name) == 0) ||
62 (vldb_id_to_name(newentry->volumeId[ROVOL], &name) == 0) ||
63 (vldb_id_to_name(newentry->volumeId[BACKVOL], &name) == 0)) {
64 free(name);
65 mlog_log (MDEBVL, "SVL_CreateEntry: id exists\n");
66 return VL_NAMEEXIST;
69 if (vldb_read_entry(newentry->name, &tempentry) == 0) {
70 mlog_log (MDEBVL, "SVL_CreateEntry: name exists\n");
71 return VL_NAMEEXIST;
74 vldb_entry_to_disk(newentry, &diskentry);
76 if (vldb_write_entry(&diskentry) != 0)
77 return VL_IO;
79 if (vldb_write_id(newentry->name,
80 newentry->volumeId[RWVOL]) != 0)
81 return VL_IO; /* XXX rollback */
83 if (vldb_write_id(newentry->name,
84 newentry->volumeId[ROVOL]) != 0)
85 return VL_IO; /* XXX rollback */
87 if (vldb_write_id(newentry->name,
88 newentry->volumeId[BACKVOL]) != 0)
89 return VL_IO; /* XXX rollback */
91 vldb_flush();
93 vldb_free_diskentry(&diskentry);
95 return 0;
98 int
99 SVL_DeleteEntry(struct rx_call *call,
100 const int32_t Volid,
101 const int32_t voltype)
103 disk_vlentry entry;
104 char *name;
105 int ret;
107 mlog_log (MDEBVL, "SVL_DeleteEntry (Volid=%d,Voltype=%d)\n",
108 Volid, voltype);
110 if (!sec_is_superuser(call)) {
111 ret = VL_PERM;
112 goto out;
115 if (voltype != RWVOL &&
116 voltype != ROVOL &&
117 voltype != BACKVOL) {
118 ret = VL_BADVOLTYPE;
119 goto out;
122 if (vldb_id_to_name(Volid, &name)) {
123 ret = VL_NOENT;
124 goto out;
127 if (vldb_read_entry(name, &entry) != 0) {
128 ret = VL_NOENT;
129 goto out;
132 if (entry.volumeId[voltype] != Volid) {
133 ret = VL_NOENT;
134 goto out;
137 if (vldb_delete_id(name, entry.volumeId[RWVOL])) {
138 mlog_log (MDEBVL, "SVL_DeleteEntry failed to remove RW id %d\n",
139 entry.volumeId[RWVOL]);
140 ret = VL_IO;
141 goto out;
143 if (vldb_delete_id(name, entry.volumeId[ROVOL])) {
144 mlog_log (MDEBVL, "SVL_DeleteEntry failed to remove RO id %d\n",
145 entry.volumeId[ROVOL]);
146 ret = VL_IO;
147 goto out;
149 if (vldb_delete_id(name, entry.volumeId[BACKVOL])) {
150 mlog_log (MDEBVL, "SVL_DeleteEntry failed to remove BK id %d\n",
151 entry.volumeId[BACKVOL]);
152 ret = VL_IO;
153 goto out;
155 if (vldb_delete_entry(name)) {
156 mlog_log (MDEBVL, "SVL_DeleteEntry failed to remove data\n");
157 ret = VL_IO;
158 goto out;
161 free(name);
163 vldb_flush();
165 ret = 0;
167 out:
168 mlog_log (MDEBVL, "SVL_DeleteEntry returns %d\n", ret);
170 return ret;
178 SVL_GetEntryByID(struct rx_call *call,
179 const int32_t Volid,
180 const int32_t voltype,
181 vldbentry *entry)
183 disk_vlentry diskentry;
184 char *name;
185 mlog_log (MDEBVL, "SVL_GetEntryByID (Volid=%d,Voltype=%d)\n",
186 Volid, voltype);
188 if (vldb_id_to_name(Volid, &name))
189 return VL_NOENT;
191 if (vldb_read_entry(name, &diskentry) != 0)
192 return VL_NOENT;
194 vldb_disk_to_entry(&diskentry, entry);
196 free(name);
198 return 0;
206 SVL_GetEntryByName(struct rx_call *call,
207 const char *volumename,
208 vldbentry *entry)
210 disk_vlentry diskentry;
212 mlog_log (MDEBVL, "SVL_GetEntryByName (volumename = %s)\n",
213 volumename);
215 if (isdigit(volumename[0])) {
216 return SVL_GetEntryByID(call, atol(volumename), 0 /* XXX */, entry);
219 if (vldb_read_entry(volumename, &diskentry) != 0)
220 return VL_NOENT;
222 vldb_disk_to_entry(&diskentry, entry);
224 return 0;
231 int
232 SVL_GetNewVolumeId (struct rx_call *call,
233 const int32_t bumpcount,
234 int32_t *newvolumid)
236 mlog_log (MDEBVL, "SVL_GetNewVolumeId(bumpcount=%d)\n", bumpcount) ;
238 if (!sec_is_superuser(call))
239 return VL_PERM;
241 *newvolumid = vl_header.MaxVolumeId;
242 mlog_log (MDEBVL, " returning low volume id = %d\n", *newvolumid);
243 vl_header.MaxVolumeId += bumpcount;
244 vldb_write_header();
246 vldb_flush();
248 return 0;
256 SVL_ReplaceEntry (struct rx_call *call,
257 const int32_t Volid,
258 const int32_t voltype,
259 const vldbentry *newentry,
260 const int32_t ReleaseType)
262 mlog_log (MDEBVL, "SVL_ReplaceEntry\n") ;
264 if (!sec_is_superuser(call))
265 return VL_PERM;
267 return VL_PERM ;
275 SVL_UpdateEntry (struct rx_call *call,
276 const int32_t Volid,
277 const int32_t voltype,
278 const VldbUpdateEntry *UpdateEntry,
279 const int32_t ReleaseType)
281 mlog_log (MDEBVL, "SVL_UpdateEntry\n") ;
283 if (!sec_is_superuser(call))
284 return VL_PERM;
286 return VL_PERM ;
293 int
294 SVL_SetLock (struct rx_call *call,
295 const int32_t Volid,
296 const int32_t voltype,
297 const int32_t voloper)
299 mlog_log (MDEBVL, "SVL_SetLock\n") ;
301 if (!sec_is_superuser(call))
302 return VL_PERM;
304 return 0;
312 SVL_ReleaseLock (struct rx_call *call,
313 const int32_t volid,
314 const int32_t voltype,
315 const int32_t ReleaseType)
317 mlog_log (MDEBVL, "SVL_ReleaseLock\n") ;
319 if (!sec_is_superuser(call))
320 return VL_PERM;
323 return 0;
331 SVL_ListEntry (struct rx_call *call,
332 const int32_t previous_index,
333 int32_t *count,
334 int32_t *next_index,
335 vldbentry *entry)
337 mlog_log (MDEBVL, "SVL_ListEntry\n") ;
338 return VL_PERM ;
346 SVL_ListAttributes (struct rx_call *call,
347 const VldbListByAttributes *attributes,
348 int32_t *nentries,
349 bulkentries *blkentries)
351 mlog_log (MDEBVL, "SVL_ListAttributes\n") ;
352 return VL_PERM ;
360 SVL_GetStats (struct rx_call *call,
361 vldstats *stats,
362 vital_vlheader *vital_header)
364 mlog_log (MDEBVL, "SVL_GetStats") ;
365 return VL_PERM ;
372 int
373 SVL_Probe(struct rx_call *call)
375 mlog_log (MDEBVL, "SVL_Probe\n") ;
376 return 0;
384 SVL_CreateEntryN(struct rx_call *call,
385 const nvldbentry *entry)
387 char *name;
388 disk_vlentry diskentry;
389 disk_vlentry tempentry;
391 mlog_log (MDEBVL, "SVL_CreateEntryN (name=%s, ids=%d,%d,%d flags=%d)\n",
392 entry->name,
393 entry->volumeId[RWVOL],
394 entry->volumeId[ROVOL],
395 entry->volumeId[BACKVOL],
396 entry->flags);
398 if (!sec_is_superuser(call))
399 return VL_PERM;
402 if ((vldb_id_to_name(entry->volumeId[RWVOL], &name) == 0) ||
403 (vldb_id_to_name(entry->volumeId[ROVOL], &name) == 0) ||
404 (vldb_id_to_name(entry->volumeId[BACKVOL], &name) == 0)) {
405 free(name);
406 mlog_log (MDEBVL, "SVL_CreateEntryN: id exists\n");
407 return VL_NAMEEXIST;
410 if (vldb_read_entry(entry->name, &tempentry) == 0) {
411 mlog_log (MDEBVL, "SVL_CreateEntryN: name exists\n");
412 return VL_NAMEEXIST;
415 vldb_nentry_to_disk(entry, &diskentry);
417 if (vldb_write_entry(&diskentry) != 0)
418 return VL_IO;
420 if (vldb_write_id(entry->name,
421 entry->volumeId[RWVOL]) != 0)
422 return VL_IO; /* XXX rollback */
424 if (vldb_write_id(entry->name,
425 entry->volumeId[ROVOL]) != 0)
426 return VL_IO; /* XXX rollback */
428 if (vldb_write_id(entry->name,
429 entry->volumeId[BACKVOL]) != 0)
430 return VL_IO; /* XXX rollback */
432 vldb_free_diskentry(&diskentry);
434 vldb_flush();
436 return 0;
444 SVL_GetEntryByIDN(struct rx_call *call,
445 const int32_t Volid,
446 const int32_t voltype,
447 nvldbentry *entry)
449 disk_vlentry diskentry;
450 char *name;
451 mlog_log (MDEBVL, "SVL_GetEntryByIDN (Volid=%d,Voltype=%d)\n",
452 Volid, voltype);
454 if (vldb_id_to_name(Volid, &name))
455 return VL_NOENT;
457 if (vldb_read_entry(name, &diskentry) != 0)
458 return VL_NOENT;
460 vldb_disk_to_nentry(&diskentry, entry);
462 free(name);
464 return 0;
472 SVL_GetEntryByNameN(struct rx_call *call,
473 const char *volumename,
474 nvldbentry *entry)
476 disk_vlentry diskentry;
478 mlog_log (MDEBVL, "SVL_GetEntryByNameN (volumename = %s)\n",
479 volumename);
481 if (isdigit(volumename[0])) {
482 return SVL_GetEntryByIDN(call, atol(volumename), 0 /* XXX */, entry);
485 if (vldb_read_entry(volumename, &diskentry) != 0)
486 return VL_NOENT;
488 vldb_disk_to_nentry(&diskentry, entry);
490 return 0;
493 #ifdef notyet
499 SVL_GetEntryByNameU(struct rx_call *call,
500 const char *volumename,
501 uvldbentry *entry)
503 mlog_log (MDEBVL, "SVL_GetEntryByNameU %s\n", volumename);
504 memset(entry, 0, sizeof(*entry));
506 return RXGEN_OPCODE;
508 #endif
515 SVL_ListAttributesN (struct rx_call *call,
516 const VldbListByAttributes *attributes,
517 int32_t *nentries,
518 nbulkentries *blkentries)
520 mlog_log (MDEBVL, "SVL_ListAttributesN\n");
521 mlog_log (MDEBVL, " attributes: Mask=(%d=", attributes->Mask);
523 if (attributes->Mask & VLLIST_SERVER)
524 mlog_log (MDEBVL, "SERVER ");
525 if (attributes->Mask & VLLIST_PARTITION)
526 mlog_log (MDEBVL, "PARTITION ");
527 if (attributes->Mask & VLLIST_VOLUMEID)
528 mlog_log (MDEBVL, "VOLUMEID ");
529 if (attributes->Mask & VLLIST_FLAG)
530 mlog_log (MDEBVL, "FLAG");
532 mlog_log (MDEBVL, ") server=%d partition=%d volumetype=%d volumeid=%d flag=%d\n",
533 attributes->server,
534 attributes->partition,
535 attributes->volumetype,
536 attributes->volumeid,
537 attributes->flag);
539 *nentries = 1;
541 blkentries->len = 0;
542 blkentries->val = NULL;
544 return VL_PERM;
547 #ifdef notyet
553 SVL_ListAttributesU(struct rx_call *call,
554 const VldbListByAttributes *attributes,
555 int32_t *nentries,
556 ubulkentries *blkentries)
558 mlog_log (MDEBVL, "SVL_ListAttributesU\n") ;
559 *nentries = 0;
560 blkentries->len = 0;
561 blkentries->val = NULL;
562 return 0;
564 #endif
571 SVL_UpdateEntryByName(struct rx_call *call,
572 const char volname[65],
573 const struct VldbUpdateEntry *UpdateEntry,
574 const int32_t ReleaseType)
576 mlog_log (MDEBVL, "SVL_UpdateEntryByName (not implemented)\n");
578 if (!sec_is_superuser(call))
579 return VL_PERM;
581 return VL_PERM;
589 SVL_GetAddrsU(struct rx_call *call,
590 const struct ListAddrByAttributes *inaddr,
591 struct afsUUID *uuid,
592 int32_t *uniq,
593 int32_t *nentries,
594 bulkaddrs *addrs)
596 mlog_log (MDEBVL, "SVL_GetAddrsU (not implemented)\n");
597 return RXGEN_OPCODE;
605 SVL_RegisterAddrs(struct rx_call *call,
606 const struct afsUUID *uid,
607 const int32_t spare,
608 const bulkaddrs *addrs)
610 mlog_log (MDEBVL, "SVL_RegistersAddrs (not implemented)\n");
612 if (!sec_is_superuser(call))
613 return VL_PERM;
615 return 0;
618 #ifdef notyet
624 SVL_CreateEntryU(struct rx_call *call,
625 const struct uvldbentry *newentry)
627 mlog_log (MDEBVL, "SVL_CreateEntryU (not implemented)\n");
629 if (!sec_is_superuser(call))
630 return VL_PERM;
632 return VL_PERM;
634 #endif
636 #ifdef notyet
642 SVL_ReplaceEntryU(struct rx_call *call)
644 mlog_log (MDEBVL, "SVL_ReplaceEntryU (not implemented)\n");
646 if (!sec_is_superuser(call))
647 return VL_PERM;
649 return VL_PERM;
651 #endif
658 SVL_ReplaceEntryN(struct rx_call *call,
659 const int32_t Volid,
660 const int32_t voltype,
661 const struct nvldbentry *newentry,
662 const int32_t ReleaseType)
664 mlog_log (MDEBVL, "SVL_ReplaceEntryN (not implemented)\n");
666 if (!sec_is_superuser(call))
667 return VL_PERM;
669 return VL_PERM;
677 SVL_ChangeAddrs(struct rx_call *call,
678 const int32_t old_ip,
679 const int32_t new_ip)
681 mlog_log (MDEBVL, "SVL_ChangeAddrs (not implemented)\n");
683 if (!sec_is_superuser(call))
684 return VL_PERM;
686 return VL_PERM;
689 #ifdef notyet
695 SVL_GetEntryByIDU(struct rx_call *call)
697 mlog_log (MDEBVL, "SVL_GetEntryByIDU (not implemented)\n");
698 return VL_PERM;
700 #endif
707 SVL_ListEntryN(struct rx_call *call,
708 int32_t previous_index,
709 int32_t *count,
710 int32_t *next_index,
711 nvldbentry *entry)
713 mlog_log (MDEBVL, "SVL_ListEntryN (not implemented)\n");
714 return VL_PERM;
717 #ifdef notyet
723 SVL_ListEntryU(struct rx_call *call)
725 mlog_log (MDEBVL, "SVL_ListEntryU (not implemented)\n");
726 return VL_PERM;
728 #endif
735 SVL_GetAddrs(struct rx_call *call,
736 const int32_t handle,
737 const int32_t spare,
738 struct VL_Callback *spare3,
739 int32_t *nentries,
740 bulkaddrs *blkaddr)
742 mlog_log (MDEBVL, "SVL_GetAddrs (not implemented)\n");
743 return VL_PERM;
746 #ifdef notyet
752 SVL_LinkedListN(struct rx_call *call)
754 mlog_log (MDEBVL, "SVL_LinkedListN (not implemented)\n");
755 return VL_PERM;
763 SVL_LinkedListU(struct rx_call *call)
765 mlog_log (MDEBVL, "SVL_LinkedListU (not implemented)\n");
766 return VL_PERM;
768 #endif
771 SVL_ListAttributesN2(struct rx_call *call,
772 const struct VldbListByAttributes *attributes,
773 const char *volumename,
774 const int32_t startindex,
775 int32_t *nentries,
776 nbulkentries *blkentries,
777 int32_t *nextstartindex)
779 mlog_log (MDEBVL, "SVL_ListAttributesN2 (not implemented)\n");
780 return VL_PERM;
786 static struct rx_service *vldbservice = NULL;
787 static struct rx_service *ubikservice = NULL;
789 static char *cell = NULL;
790 static char *realm = NULL;
791 static char *srvtab_file = NULL;
792 static char *log_file = "syslog";
793 static char *debug_levels = NULL;
794 static int no_auth = 0;
795 static int do_help = 0;
796 static char *databasedir = NULL;
797 static int do_create = 0;
799 static struct agetargs args[] = {
800 {"cell", 0, aarg_string, &cell, "what cell to use"},
801 {"realm", 0, aarg_string, &realm, "what realm to use"},
802 {"debug", 'd', aarg_string, &debug_levels, "debug level"},
803 {"log", 'l', aarg_string, &log_file,
804 "where to write log (stderr, syslog (default), or path to file)"},
805 {"srvtab", 0, aarg_string, &srvtab_file, "what srvtab to use"},
806 {"noauth", 0, aarg_flag, &no_auth, "disable authentication checks"},
807 {"help", 'h', aarg_flag, &do_help, "help"},
808 {"dbdir", 0, aarg_string, &databasedir, "where to store the db"},
809 {"create", 0, aarg_flag, &do_create, "create new database"},
810 { NULL, 0, aarg_end, NULL }
813 static void
814 usage(int exit_code)
816 aarg_printusage (args, NULL, "", AARG_GNUSTYLE);
817 exit (exit_code);
821 main(int argc, char **argv)
823 Log_method *method;
824 int optind = 0;
825 int ret;
827 setprogname (argv[0]);
829 if (agetarg (args, argc, argv, &optind, AARG_GNUSTYLE)) {
830 usage (1);
833 argc -= optind;
834 argv += optind;
836 if (argc) {
837 printf("unknown option %s\n", *argv);
838 return 1;
841 if (do_help)
842 usage(0);
844 if (no_auth)
845 sec_disable_superuser_check ();
847 method = log_open (getprogname(), log_file);
848 if (method == NULL)
849 errx (1, "log_open failed");
850 cell_init(0, method);
851 ports_init();
853 mlog_loginit (method, milko_deb_units, MDEFAULT_LOG);
855 if (debug_levels)
856 mlog_log_set_level (debug_levels);
858 if (cell)
859 cell_setthiscell (cell);
861 network_kerberos_init (srvtab_file);
863 if (do_create) {
864 vldb_create (databasedir);
865 vldb_close();
866 return 0;
869 vldb_init(databasedir);
871 ret = network_init(htons(afsvldbport), "vl", VLDB_SERVICE_ID,
872 VL_ExecuteRequest, &vldbservice, realm);
873 if (ret)
874 errx (1, "network_init failed with %d", ret);
876 ret = network_init(htons(afsvldbport), "ubik", VOTE_SERVICE_ID,
877 Ubik_ExecuteRequest, &ubikservice, realm);
878 if (ret)
879 errx (1, "network_init failed with %d", ret);
881 printf("Milko vldbserver %s-%s started\n", PACKAGE, VERSION);
883 rx_SetMaxProcs(vldbservice,5) ;
884 rx_SetMaxProcs(ubikservice,5) ;
885 rx_StartServer(1) ;
887 abort() ; /* should not get here */
888 return 0;