From 8cd1dc27dc16349b94c66eec721191d5dff29dab Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 11 Aug 2009 08:59:39 -0400 Subject: [PATCH] Windows: Setting Server Preferences The Windows cache manager can apply administrator specified server preferences as specified in the registry. When these rankings are applied the CM_SERVERFLAG_PREF_SET flag was not set on the cm_server_t object. In addition, appropriate locking was not being used in the places where the flag was set. LICENSE MIT Reviewed-on: http://gerrit.openafs.org/303 Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsd/afsd_init.c | 16 ++++++++++++++-- src/WINNT/afsd/cm_ioctl.c | 29 +++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index 455a03afb..d6d1d4641 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -303,7 +303,10 @@ static void afsd_InitServerPreferences(void) tsp = cm_FindServer(&saddr, CM_SERVER_VLDB); if ( tsp ) /* an existing server - ref count increased */ { - tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/ + lock_ObtainMutex(&tsp->mx); + tsp->ipRank = (USHORT)dwRank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); /* set preferences for an existing vlserver */ cm_ChangeRankCellVLServer(tsp); @@ -312,7 +315,10 @@ static void afsd_InitServerPreferences(void) else /* add a new server without a cell */ { tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */ + lock_ObtainMutex(&tsp->mx); tsp->ipRank = (USHORT)dwRank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); } } @@ -370,7 +376,10 @@ static void afsd_InitServerPreferences(void) tsp = cm_FindServer(&saddr, CM_SERVER_FILE); if ( tsp ) /* an existing server - ref count increased */ { - tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/ + lock_ObtainMutex(&tsp->mx); + tsp->ipRank = (USHORT)dwRank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); /* find volumes which might have RO copy /* on server and change the ordering of @@ -382,7 +391,10 @@ static void afsd_InitServerPreferences(void) else /* add a new server without a cell */ { tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */ + lock_ObtainMutex(&tsp->mx); tsp->ipRank = (USHORT)dwRank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); } } diff --git a/src/WINNT/afsd/cm_ioctl.c b/src/WINNT/afsd/cm_ioctl.c index 495d239a7..66fce80f5 100644 --- a/src/WINNT/afsd/cm_ioctl.c +++ b/src/WINNT/afsd/cm_ioctl.c @@ -1753,30 +1753,35 @@ cm_IoctlSetSPrefs(struct cm_ioctl *ioctlp, struct cm_user *userp) tsp = cm_FindServer(&tmp, type); if ( tsp ) /* an existing server - ref count increased */ { - tsp->ipRank = rank; /* no need to protect by mutex*/ - - if (type == CM_SERVER_FILE) - { /* fileserver */ - /* find volumes which might have RO copy - /* on server and change the ordering of + lock_ObtainMutex(&tsp->mx); + tsp->ipRank = rank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); + + switch (type) { + case CM_SERVER_FILE: + /* + * find volumes which might have RO copy + * on server and change the ordering of * their RO list */ cm_ChangeRankVolume(tsp); - } - else - { + break; + case CM_SERVER_VLDB: /* set preferences for an existing vlserver */ cm_ChangeRankCellVLServer(tsp); + break; } } else /* add a new server without a cell */ { tsp = cm_NewServer(&tmp, type, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */ + lock_ObtainMutex(&tsp->mx); + tsp->ipRank = rank; + tsp->flags |= CM_SERVERFLAG_PREF_SET; + lock_ReleaseMutex(&tsp->mx); tsp->ipRank = rank; } - lock_ObtainMutex(&tsp->mx); - tsp->flags |= CM_SERVERFLAG_PREF_SET; - lock_ReleaseMutex(&tsp->mx); cm_PutServer(tsp); /* decrease refcount */ } return 0; -- 2.39.5