2 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 #include "vldb_locl.h"
43 SVL_CreateEntry(struct rx_call
*call
,
44 const vldbentry
*newentry
)
47 disk_vlentry diskentry
;
48 disk_vlentry tempentry
;
50 mlog_log (MDEBVL
, "SVL_CreateEntry (name=%s, ids=%d,%d,%d flags=%d)\n",
52 newentry
->volumeId
[RWVOL
],
53 newentry
->volumeId
[ROVOL
],
54 newentry
->volumeId
[BACKVOL
],
58 if (!sec_is_superuser(call
))
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)) {
65 mlog_log (MDEBVL
, "SVL_CreateEntry: id exists\n");
69 if (vldb_read_entry(newentry
->name
, &tempentry
) == 0) {
70 mlog_log (MDEBVL
, "SVL_CreateEntry: name exists\n");
74 vldb_entry_to_disk(newentry
, &diskentry
);
76 if (vldb_write_entry(&diskentry
) != 0)
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 */
93 vldb_free_diskentry(&diskentry
);
99 SVL_DeleteEntry(struct rx_call
*call
,
101 const int32_t voltype
)
107 mlog_log (MDEBVL
, "SVL_DeleteEntry (Volid=%d,Voltype=%d)\n",
110 if (!sec_is_superuser(call
)) {
115 if (voltype
!= RWVOL
&&
117 voltype
!= BACKVOL
) {
122 if (vldb_id_to_name(Volid
, &name
)) {
127 if (vldb_read_entry(name
, &entry
) != 0) {
132 if (entry
.volumeId
[voltype
] != Volid
) {
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
]);
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
]);
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
]);
155 if (vldb_delete_entry(name
)) {
156 mlog_log (MDEBVL
, "SVL_DeleteEntry failed to remove data\n");
168 mlog_log (MDEBVL
, "SVL_DeleteEntry returns %d\n", ret
);
178 SVL_GetEntryByID(struct rx_call
*call
,
180 const int32_t voltype
,
183 disk_vlentry diskentry
;
185 mlog_log (MDEBVL
, "SVL_GetEntryByID (Volid=%d,Voltype=%d)\n",
188 if (vldb_id_to_name(Volid
, &name
))
191 if (vldb_read_entry(name
, &diskentry
) != 0)
194 vldb_disk_to_entry(&diskentry
, entry
);
206 SVL_GetEntryByName(struct rx_call
*call
,
207 const char *volumename
,
210 disk_vlentry diskentry
;
212 mlog_log (MDEBVL
, "SVL_GetEntryByName (volumename = %s)\n",
215 if (isdigit(volumename
[0])) {
216 return SVL_GetEntryByID(call
, atol(volumename
), 0 /* XXX */, entry
);
219 if (vldb_read_entry(volumename
, &diskentry
) != 0)
222 vldb_disk_to_entry(&diskentry
, entry
);
232 SVL_GetNewVolumeId (struct rx_call
*call
,
233 const int32_t bumpcount
,
236 mlog_log (MDEBVL
, "SVL_GetNewVolumeId(bumpcount=%d)\n", bumpcount
) ;
238 if (!sec_is_superuser(call
))
241 *newvolumid
= vl_header
.MaxVolumeId
;
242 mlog_log (MDEBVL
, " returning low volume id = %d\n", *newvolumid
);
243 vl_header
.MaxVolumeId
+= bumpcount
;
256 SVL_ReplaceEntry (struct rx_call
*call
,
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
))
275 SVL_UpdateEntry (struct rx_call
*call
,
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
))
294 SVL_SetLock (struct rx_call
*call
,
296 const int32_t voltype
,
297 const int32_t voloper
)
299 mlog_log (MDEBVL
, "SVL_SetLock\n") ;
301 if (!sec_is_superuser(call
))
312 SVL_ReleaseLock (struct rx_call
*call
,
314 const int32_t voltype
,
315 const int32_t ReleaseType
)
317 mlog_log (MDEBVL
, "SVL_ReleaseLock\n") ;
319 if (!sec_is_superuser(call
))
331 SVL_ListEntry (struct rx_call
*call
,
332 const int32_t previous_index
,
337 mlog_log (MDEBVL
, "SVL_ListEntry\n") ;
346 SVL_ListAttributes (struct rx_call
*call
,
347 const VldbListByAttributes
*attributes
,
349 bulkentries
*blkentries
)
351 mlog_log (MDEBVL
, "SVL_ListAttributes\n") ;
360 SVL_GetStats (struct rx_call
*call
,
362 vital_vlheader
*vital_header
)
364 mlog_log (MDEBVL
, "SVL_GetStats") ;
373 SVL_Probe(struct rx_call
*call
)
375 mlog_log (MDEBVL
, "SVL_Probe\n") ;
384 SVL_CreateEntryN(struct rx_call
*call
,
385 const nvldbentry
*entry
)
388 disk_vlentry diskentry
;
389 disk_vlentry tempentry
;
391 mlog_log (MDEBVL
, "SVL_CreateEntryN (name=%s, ids=%d,%d,%d flags=%d)\n",
393 entry
->volumeId
[RWVOL
],
394 entry
->volumeId
[ROVOL
],
395 entry
->volumeId
[BACKVOL
],
398 if (!sec_is_superuser(call
))
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)) {
406 mlog_log (MDEBVL
, "SVL_CreateEntryN: id exists\n");
410 if (vldb_read_entry(entry
->name
, &tempentry
) == 0) {
411 mlog_log (MDEBVL
, "SVL_CreateEntryN: name exists\n");
415 vldb_nentry_to_disk(entry
, &diskentry
);
417 if (vldb_write_entry(&diskentry
) != 0)
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
);
444 SVL_GetEntryByIDN(struct rx_call
*call
,
446 const int32_t voltype
,
449 disk_vlentry diskentry
;
451 mlog_log (MDEBVL
, "SVL_GetEntryByIDN (Volid=%d,Voltype=%d)\n",
454 if (vldb_id_to_name(Volid
, &name
))
457 if (vldb_read_entry(name
, &diskentry
) != 0)
460 vldb_disk_to_nentry(&diskentry
, entry
);
472 SVL_GetEntryByNameN(struct rx_call
*call
,
473 const char *volumename
,
476 disk_vlentry diskentry
;
478 mlog_log (MDEBVL
, "SVL_GetEntryByNameN (volumename = %s)\n",
481 if (isdigit(volumename
[0])) {
482 return SVL_GetEntryByIDN(call
, atol(volumename
), 0 /* XXX */, entry
);
485 if (vldb_read_entry(volumename
, &diskentry
) != 0)
488 vldb_disk_to_nentry(&diskentry
, entry
);
499 SVL_GetEntryByNameU(struct rx_call
*call
,
500 const char *volumename
,
503 mlog_log (MDEBVL
, "SVL_GetEntryByNameU %s\n", volumename
);
504 memset(entry
, 0, sizeof(*entry
));
515 SVL_ListAttributesN (struct rx_call
*call
,
516 const VldbListByAttributes
*attributes
,
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",
534 attributes
->partition
,
535 attributes
->volumetype
,
536 attributes
->volumeid
,
542 blkentries
->val
= NULL
;
553 SVL_ListAttributesU(struct rx_call
*call
,
554 const VldbListByAttributes
*attributes
,
556 ubulkentries
*blkentries
)
558 mlog_log (MDEBVL
, "SVL_ListAttributesU\n") ;
561 blkentries
->val
= NULL
;
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
))
589 SVL_GetAddrsU(struct rx_call
*call
,
590 const struct ListAddrByAttributes
*inaddr
,
591 struct afsUUID
*uuid
,
596 mlog_log (MDEBVL
, "SVL_GetAddrsU (not implemented)\n");
605 SVL_RegisterAddrs(struct rx_call
*call
,
606 const struct afsUUID
*uid
,
608 const bulkaddrs
*addrs
)
610 mlog_log (MDEBVL
, "SVL_RegistersAddrs (not implemented)\n");
612 if (!sec_is_superuser(call
))
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
))
642 SVL_ReplaceEntryU(struct rx_call
*call
)
644 mlog_log (MDEBVL
, "SVL_ReplaceEntryU (not implemented)\n");
646 if (!sec_is_superuser(call
))
658 SVL_ReplaceEntryN(struct rx_call
*call
,
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
))
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
))
695 SVL_GetEntryByIDU(struct rx_call
*call
)
697 mlog_log (MDEBVL
, "SVL_GetEntryByIDU (not implemented)\n");
707 SVL_ListEntryN(struct rx_call
*call
,
708 int32_t previous_index
,
713 mlog_log (MDEBVL
, "SVL_ListEntryN (not implemented)\n");
723 SVL_ListEntryU(struct rx_call
*call
)
725 mlog_log (MDEBVL
, "SVL_ListEntryU (not implemented)\n");
735 SVL_GetAddrs(struct rx_call
*call
,
736 const int32_t handle
,
738 struct VL_Callback
*spare3
,
742 mlog_log (MDEBVL
, "SVL_GetAddrs (not implemented)\n");
752 SVL_LinkedListN(struct rx_call
*call
)
754 mlog_log (MDEBVL
, "SVL_LinkedListN (not implemented)\n");
763 SVL_LinkedListU(struct rx_call
*call
)
765 mlog_log (MDEBVL
, "SVL_LinkedListU (not implemented)\n");
771 SVL_ListAttributesN2(struct rx_call
*call
,
772 const struct VldbListByAttributes
*attributes
,
773 const char *volumename
,
774 const int32_t startindex
,
776 nbulkentries
*blkentries
,
777 int32_t *nextstartindex
)
779 mlog_log (MDEBVL
, "SVL_ListAttributesN2 (not implemented)\n");
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
}
816 aarg_printusage (args
, NULL
, "", AARG_GNUSTYLE
);
821 main(int argc
, char **argv
)
827 setprogname (argv
[0]);
829 if (agetarg (args
, argc
, argv
, &optind
, AARG_GNUSTYLE
)) {
837 printf("unknown option %s\n", *argv
);
845 sec_disable_superuser_check ();
847 method
= log_open (getprogname(), log_file
);
849 errx (1, "log_open failed");
850 cell_init(0, method
);
853 mlog_loginit (method
, milko_deb_units
, MDEFAULT_LOG
);
856 mlog_log_set_level (debug_levels
);
859 cell_setthiscell (cell
);
861 network_kerberos_init (srvtab_file
);
864 vldb_create (databasedir
);
869 vldb_init(databasedir
);
871 ret
= network_init(htons(afsvldbport
), "vl", VLDB_SERVICE_ID
,
872 VL_ExecuteRequest
, &vldbservice
, realm
);
874 errx (1, "network_init failed with %d", ret
);
876 ret
= network_init(htons(afsvldbport
), "ubik", VOTE_SERVICE_ID
,
877 Ubik_ExecuteRequest
, &ubikservice
, realm
);
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) ;
887 abort() ; /* should not get here */